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:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user