Refactorings, error handling and logout

This commit is contained in:
Dries Augustyns
2025-12-03 20:39:11 +01:00
parent 113b94cf2c
commit 382e97e5b2
12 changed files with 306 additions and 189 deletions
+23 -2
View File
@@ -109,7 +109,28 @@ export class DomainService {
);
}
// Check if domain is used in any campaigns
// Check if domain is used in any workflow steps (via templates)
const workflowStepsUsingDomain = await prisma.workflowStep.count({
where: {
workflow: {
projectId: domain.projectId,
},
template: {
from: {
contains: `@${domainName}`,
},
},
},
});
if (workflowStepsUsingDomain > 0) {
throw new HttpException(
409,
`Cannot delete domain: it is currently used in ${workflowStepsUsingDomain} workflow step(s). Update the workflow templates first.`,
);
}
// Check if domain is used in any active campaigns
const campaignsUsingDomain = await prisma.campaign.count({
where: {
projectId: domain.projectId,
@@ -117,7 +138,7 @@ export class DomainService {
contains: `@${domainName}`,
},
status: {
not: 'SENT', // Allow deletion if all campaigns using it are completed
in: ['DRAFT', 'SCHEDULED', 'SENDING'],
},
},
});