Fix issue where email would still be required for personalized vouchers in the backend #19
@@ -129,12 +129,13 @@ vouchersAdminRouter.post('/wildcard', async (req: Request, res: Response) => {
|
|||||||
* type: array
|
* type: array
|
||||||
* items:
|
* items:
|
||||||
* type: object
|
* type: object
|
||||||
* required: [name, email, eventIds]
|
* required: [name, eventIds]
|
||||||
* properties:
|
* properties:
|
||||||
* name:
|
* name:
|
||||||
* type: string
|
* type: string
|
||||||
* email:
|
* email:
|
||||||
* type: string
|
* type: string
|
||||||
|
* description: Optional - a guest can supply their own email when redeeming.
|
||||||
* eventIds:
|
* eventIds:
|
||||||
* type: array
|
* type: array
|
||||||
* items:
|
* items:
|
||||||
|
|||||||
@@ -123,10 +123,10 @@ export const generatePersonalizedBatch = async (rows: PersonalizedRowInput[], cr
|
|||||||
throw new Error('at least one row is required');
|
throw new Error('at least one row is required');
|
||||||
}
|
}
|
||||||
for (const row of rows) {
|
for (const row of rows) {
|
||||||
if (!row.name || !row.email || row.eventIds.length === 0) {
|
if (!row.name || row.eventIds.length === 0) {
|
||||||
throw new Error('each row requires a name, email, and at least one eligible event');
|
throw new Error('each row requires a name and at least one eligible event');
|
||||||
}
|
}
|
||||||
if (!isValidEmail(row.email)) {
|
if (row.email && !isValidEmail(row.email)) {
|
||||||
throw new Error(`"${row.email}" does not look like a valid email address`);
|
throw new Error(`"${row.email}" does not look like a valid email address`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -147,7 +147,7 @@ export const generatePersonalizedBatch = async (rows: PersonalizedRowInput[], cr
|
|||||||
codes.push(code);
|
codes.push(code);
|
||||||
await conn.query(
|
await conn.query(
|
||||||
'INSERT INTO voucher_codes (code, status, max_guests, prefill_name, prefill_email, batch_id, created_by_email) VALUES (?,?,?,?,?,?,?)',
|
'INSERT INTO voucher_codes (code, status, max_guests, prefill_name, prefill_email, batch_id, created_by_email) VALUES (?,?,?,?,?,?,?)',
|
||||||
[code, 'UNUSED', row.maxGuests, row.name, row.email, batchId, createdByEmail]
|
[code, 'UNUSED', row.maxGuests, row.name, row.email || null, batchId, createdByEmail]
|
||||||
);
|
);
|
||||||
for (const eventId of row.eventIds) {
|
for (const eventId of row.eventIds) {
|
||||||
await conn.query('INSERT INTO voucher_code_events (code, event_id) VALUES (?,?)', [code, eventId]);
|
await conn.query('INSERT INTO voucher_code_events (code, event_id) VALUES (?,?)', [code, eventId]);
|
||||||
|
|||||||
Reference in New Issue
Block a user