fix: cascade-delete stale ClaimFile rows and sync claim attachments

Deleting/replacing an appointment attachment left an orphaned ClaimFile
copy behind (auto-linked earlier by autoLinkAppointmentFiles), causing
the Selenium claim automation to upload extra files beyond what's
currently attached to the appointment. Claim PUT was also append-only
for claimFiles, so removing an attachment in the UI never persisted.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-29 22:57:21 -04:00
co-authored by Claude Sonnet 5
parent 65dc795eb2
commit 6d0838446b
2 changed files with 27 additions and 4 deletions
@@ -237,6 +237,12 @@ export const appointmentProceduresStorage: IAppointmentProceduresStorage = {
await db.appointmentFile.delete({ where: { id: fileId } });
// Remove any ClaimFile copies previously auto-linked from this appointment file
// so a deleted/replaced attachment doesn't linger on the claim and get re-uploaded.
await db.claimFile.deleteMany({
where: { filename: file.filename, claim: { appointmentId } },
});
// Best-effort cleanup of the underlying cloud-storage file/disk copy.
if (file.filePath) {
const cloudFile = await db.cloudFile.findFirst({