improvement: attachment selection for lab dispatch added. attachment preview added to cases feature.

This commit is contained in:
2026-07-07 18:43:10 +03:30
parent b2d40b3e97
commit 86b1e3afff
25 changed files with 767 additions and 84 deletions

View File

@@ -56,6 +56,13 @@ const treatmentInclude = {
include: { organization: { select: { id: true, name: true } } },
},
toothProsthesis: true,
attachments: {
include: {
attachment: {
select: { id: true, fileName: true, mimeType: true, sizeBytes: true, createdAt: true },
},
},
},
},
},
};
@@ -427,6 +434,29 @@ export class TreatmentsService {
})),
});
}
await tx.labCaseAttachment.deleteMany({ where: { labCaseId: row.id } });
const attachmentIds = lc.attachmentIds ?? [];
if (attachmentIds.length > 0) {
const validAttachments = await tx.treatmentDetailAttachment.findMany({
where: {
id: { in: attachmentIds },
detailId: { in: lc.treatmentDetailIds },
},
select: { id: true },
});
if (validAttachments.length !== attachmentIds.length) {
throw new BadRequestException(
'One or more attachments are invalid for this lab case',
);
}
await tx.labCaseAttachment.createMany({
data: attachmentIds.map((attachmentId) => ({
labCaseId: row.id,
attachmentId,
})),
});
}
}
return tx.treatment.findUniqueOrThrow({
@@ -766,6 +796,15 @@ export class TreatmentsService {
tooth: string;
prosthesisTypeCode: string;
}>;
attachments?: Array<{
attachment: {
id: string;
fileName: string;
mimeType: string;
sizeBytes: number;
createdAt: Date;
};
}>;
}) {
return {
id: lc.id,
@@ -784,6 +823,13 @@ export class TreatmentsService {
tooth: tp.tooth,
prosthesisTypeCode: tp.prosthesisTypeCode,
})),
attachments: (lc.attachments ?? []).map((row) => ({
id: row.attachment.id,
fileName: row.attachment.fileName,
mimeType: row.attachment.mimeType,
sizeBytes: row.attachment.sizeBytes,
createdAt: row.attachment.createdAt.toISOString(),
})),
sends:
lc.sends?.map((s) => ({
organizationId: s.organizationId,