feat: vylepšení funkce objednávání
CI / Generate TypeScript types (push) Successful in 1m24s
CI / Build server (push) Successful in 26s
CI / Build client (push) Successful in 41s
CI / Server unit tests (push) Successful in 3m25s
CI / Playwright E2E tests (push) Has been cancelled
CI / Build and push Docker image (push) Has been cancelled
CI / Notify (push) Has been cancelled
CI / Generate TypeScript types (push) Successful in 1m24s
CI / Build server (push) Successful in 26s
CI / Build client (push) Successful in 41s
CI / Server unit tests (push) Successful in 3m25s
CI / Playwright E2E tests (push) Has been cancelled
CI / Build and push Docker image (push) Has been cancelled
CI / Notify (push) Has been cancelled
This commit is contained in:
@@ -131,6 +131,7 @@ export async function setGroupState(login: string, groupId: string, newState: Gr
|
||||
await removePendingQrsByGroupId(memberLogins, groupId);
|
||||
group.orderedAt = undefined;
|
||||
group.deliveryAt = undefined;
|
||||
group.qrGenerated = undefined;
|
||||
for (const ml of memberLogins) {
|
||||
group.members[ml] = { ...group.members[ml], paid: undefined };
|
||||
}
|
||||
@@ -139,6 +140,16 @@ export async function setGroupState(login: string, groupId: string, newState: Gr
|
||||
return saveExtraData(data, date);
|
||||
}
|
||||
|
||||
export async function markGroupQrGenerated(login: string, groupId: string, date?: Date): Promise<void> {
|
||||
const data = await getExtraData(date);
|
||||
const group = findGroup(data, groupId);
|
||||
if (!group) throw new Error('Skupina nebyla nalezena');
|
||||
if (group.creatorLogin !== login) throw new Error('QR kódy může generovat pouze zakladatel');
|
||||
if (group.state !== GroupState.ORDERED) throw new Error('QR kódy lze generovat pouze ve stavu "objednáno"');
|
||||
group.qrGenerated = true;
|
||||
await saveExtraData(data, date);
|
||||
}
|
||||
|
||||
export async function markGroupMemberPaid(login: string, groupId: string, date?: Date): Promise<ClientData | null> {
|
||||
const data = await getExtraData(date);
|
||||
const group = findGroup(data, groupId);
|
||||
|
||||
+2
-4
@@ -56,10 +56,8 @@ function createStorageKey(customerName: string, id: string): string {
|
||||
* @param id unikátní identifikátor (UUID) tohoto QR kódu
|
||||
*/
|
||||
export async function generateQr(customerName: string, bankAccountNumber: string, bankAccountHolder: string, amount: number, message: string, id: string): Promise<void> {
|
||||
// Zpráva pro příjemce nesmí dle standardu obsahovat '*' a být delší než 60 znaků
|
||||
if (message.indexOf('*') >= 0) {
|
||||
message = message.replace(/\*/g, '');
|
||||
}
|
||||
// Zpráva nesmí obsahovat '*' a znaky mimo ISO 8859-1; délka max. 60 znaků
|
||||
message = message.replace(/[^\x00-\xff]/g, '').replace(/\*/g, '');
|
||||
if (message.length > 60) {
|
||||
message = message.substring(0, 60);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { getLogin } from "../auth";
|
||||
import { parseToken, formatDate } from "../utils";
|
||||
import { generateQr } from "../qr";
|
||||
import { addPendingQr } from "../pizza";
|
||||
import { markGroupQrGenerated } from "../groups";
|
||||
import { emitToUser } from "../websocket";
|
||||
import { GenerateQrData } from "../../../types";
|
||||
import crypto from "crypto";
|
||||
@@ -57,6 +58,10 @@ router.post("/generate", async (req: Request<{}, any, GenerateQrData["body"]>, r
|
||||
emitToUser(recipient.login, 'pendingQr', pendingQr);
|
||||
}
|
||||
|
||||
if (groupId) {
|
||||
await markGroupQrGenerated(login, groupId);
|
||||
}
|
||||
|
||||
res.status(200).json({ success: true, count: recipients.length });
|
||||
} catch (e: any) {
|
||||
next(e);
|
||||
|
||||
Reference in New Issue
Block a user