Add ability to edit participant name and phone number

This commit is contained in:
2026-01-06 02:59:14 +01:00
parent 427da6452a
commit 97f9b60619
3 changed files with 154 additions and 0 deletions

View File

@@ -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;

View File

@@ -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));