add edit & delete button to tender & update contacts dashbaord
This commit is contained in:
@@ -125,6 +125,62 @@ class TendersService {
|
||||
}
|
||||
}
|
||||
|
||||
async delete(id: string, userId: string) {
|
||||
const tender = await prisma.tender.findUnique({
|
||||
where: { id },
|
||||
include: {
|
||||
attachments: true,
|
||||
directives: {
|
||||
include: {
|
||||
attachments: true,
|
||||
},
|
||||
},
|
||||
convertedDeal: {
|
||||
select: { id: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!tender) {
|
||||
throw new AppError(404, 'Tender not found');
|
||||
}
|
||||
|
||||
if (tender.convertedDeal) {
|
||||
throw new AppError(400, 'Cannot delete tender that has been converted to deal');
|
||||
}
|
||||
|
||||
for (const attachment of tender.attachments || []) {
|
||||
if (attachment.path && fs.existsSync(attachment.path)) {
|
||||
fs.unlinkSync(attachment.path);
|
||||
}
|
||||
}
|
||||
|
||||
for (const directive of tender.directives || []) {
|
||||
for (const attachment of directive.attachments || []) {
|
||||
if (attachment.path && fs.existsSync(attachment.path)) {
|
||||
fs.unlinkSync(attachment.path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await prisma.tender.delete({
|
||||
where: { id },
|
||||
});
|
||||
|
||||
await AuditLogger.log({
|
||||
entityType: 'TENDER',
|
||||
entityId: id,
|
||||
action: 'DELETE',
|
||||
userId,
|
||||
changes: {
|
||||
deletedTenderNumber: tender.tenderNumber,
|
||||
deletedTitle: tender.title,
|
||||
},
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private buildTenderNotes(
|
||||
plainNotes?: string | null,
|
||||
extra?: {
|
||||
|
||||
Reference in New Issue
Block a user