mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-09 13:01:00 +00:00
Drop the column fallback around the medication update
The update retried without pausedAt and notificationsEnabled for a database that lacked the columns. Migrations guarantee both, and inside the transaction a failed statement aborts it, so the retry could not work anyway.
This commit is contained in:
1 parent
43a53255c9
commit
c7a2eec078
1 file changed
+5
-36
@@ -969,42 +969,11 @@ export const PUT = apiHandler(
|
||||
}),
|
||||
};
|
||||
|
||||
const withoutNotifications = { ...baseUpdateData } as Record<
|
||||
string,
|
||||
unknown
|
||||
>;
|
||||
delete withoutNotifications.notificationsEnabled;
|
||||
const hasPausedAtPatch = Object.keys(pausedAtPatch).length > 0;
|
||||
const hasNotificationsPatch = notificationsEnabled !== undefined;
|
||||
|
||||
const updateCandidates: Array<Record<string, unknown>> = [
|
||||
{ ...baseUpdateData, ...pausedAtPatch },
|
||||
];
|
||||
if (hasPausedAtPatch) {
|
||||
updateCandidates.push(baseUpdateData);
|
||||
}
|
||||
if (hasNotificationsPatch) {
|
||||
updateCandidates.push({ ...withoutNotifications, ...pausedAtPatch });
|
||||
if (hasPausedAtPatch) {
|
||||
updateCandidates.push(withoutNotifications);
|
||||
}
|
||||
}
|
||||
|
||||
let updated;
|
||||
let lastUpdateErr: unknown;
|
||||
for (const candidate of updateCandidates) {
|
||||
try {
|
||||
updated = await tx.medication.update({
|
||||
where: { id },
|
||||
data: candidate,
|
||||
include: { schedules: true },
|
||||
});
|
||||
break;
|
||||
} catch (updateErr) {
|
||||
lastUpdateErr = updateErr;
|
||||
}
|
||||
}
|
||||
if (!updated) throw lastUpdateErr;
|
||||
const updated = await tx.medication.update({
|
||||
where: { id },
|
||||
data: { ...baseUpdateData, ...pausedAtPatch },
|
||||
include: { schedules: true },
|
||||
});
|
||||
|
||||
// v1.25 H-MED1 — durable pause intervals. The `pausedAt` column is a
|
||||
// single live marker that resume clears, so the paused window is
|
||||
|
||||
Reference in new issue
Block a user