From 18d1004c65d3344d2f71409c645ef104cd16513d Mon Sep 17 00:00:00 2001 From: Potenz Date: Tue, 11 Nov 2025 17:03:00 +0530 Subject: [PATCH] feat - aptmnt status updation upon new date --- apps/Backend/src/routes/appointments.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/apps/Backend/src/routes/appointments.ts b/apps/Backend/src/routes/appointments.ts index 0a86b50..2dd8ae0 100644 --- a/apps/Backend/src/routes/appointments.ts +++ b/apps/Backend/src/routes/appointments.ts @@ -365,10 +365,23 @@ router.put( }); } + // 6. if date gets updated, then also update the aptmnt status to unknown. + // Normalize to YYYY-MM-DD to avoid timezone problems (model uses @db.Date) + const oldYMD = new Date(existingAppointment.date) + .toISOString() + .slice(0, 10); + const newYMD = new Date(date).toISOString().slice(0, 10); + const isDateChanged = oldYMD !== newYMD; + + const updatePayload = { + ...appointmentData, + ...(isDateChanged ? { eligibilityStatus: "UNKNOWN" as const } : {}), + }; + // Update appointment const updatedAppointment = await storage.updateAppointment( appointmentId, - appointmentData + updatePayload ); return res.json(updatedAppointment); } catch (error) {