Add ability to edit participant name and phone number
This commit is contained in:
@@ -339,6 +339,10 @@ export const participantOps = {
|
||||
db.prepare('DELETE FROM participants WHERE id = ?').run(id);
|
||||
},
|
||||
|
||||
update: (id: number, name: string, phone: string | null): void => {
|
||||
db.prepare('UPDATE participants SET name = ?, phone = ? WHERE id = ?').run(name, phone, id);
|
||||
},
|
||||
|
||||
isTokenAvailable: (token: string): boolean => {
|
||||
const result = db.prepare('SELECT id FROM participants WHERE token = ?').get(token);
|
||||
return !result;
|
||||
|
||||
@@ -225,6 +225,30 @@ router.post('/questionnaires/:id/participants', (req: Request, res: Response) =>
|
||||
res.json({ success: true, participant });
|
||||
});
|
||||
|
||||
// Update participant
|
||||
router.put('/participants/:id', (req: Request, res: Response) => {
|
||||
const { name, phone } = req.body;
|
||||
const participant = participantOps.findById(parseInt(req.params.id));
|
||||
|
||||
if (!participant) {
|
||||
res.status(404).json({ error: 'Deelnemer niet gevonden' });
|
||||
return;
|
||||
}
|
||||
|
||||
if (!name?.trim()) {
|
||||
res.status(400).json({ error: 'Naam is verplicht' });
|
||||
return;
|
||||
}
|
||||
|
||||
// Clean phone number (remove spaces, keep + and digits) or set to null if empty
|
||||
const cleanPhone = phone?.trim() ? phone.trim().replace(/[^\d+]/g, '') : null;
|
||||
|
||||
participantOps.update(participant.id, name.trim(), cleanPhone);
|
||||
const updated = participantOps.findById(participant.id);
|
||||
|
||||
res.json({ success: true, participant: updated });
|
||||
});
|
||||
|
||||
// Delete participant
|
||||
router.delete('/participants/:id', (req: Request, res: Response) => {
|
||||
participantOps.delete(parseInt(req.params.id));
|
||||
|
||||
Reference in New Issue
Block a user