Add ability to edit participant name and phone number
This commit is contained in:
@@ -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