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
+5
View File
@@ -116,6 +116,11 @@ export class CampaignService {
}
if (data.segmentId !== undefined) {
// Prevent changing segment on scheduled campaigns
if (campaign.status === CampaignStatus.SCHEDULED) {
throw new HttpException(400, 'Cannot change segment for scheduled campaigns');
}
if (data.segmentId) {
const segment = await prisma.segment.findFirst({
where: {id: data.segmentId, projectId},
+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'],
},
},
});
+2 -2
View File
@@ -180,12 +180,12 @@ export class SegmentService {
// First verify segment exists and belongs to project
await this.get(projectId, segmentId);
// Check if segment is used in any campaigns
// Check if segment is used in any active campaigns
const campaignsUsingSegment = await prisma.campaign.count({
where: {
segmentId,
status: {
not: 'SENT', // Allow deletion if all campaigns using it are completed
in: ['DRAFT', 'SCHEDULED', 'SENDING'],
},
},
});
+10
View File
@@ -242,6 +242,16 @@ export class WorkflowService {
// Verify workflow exists and belongs to project
const workflow = await this.get(projectId, workflowId);
// Check if workflow has active executions
const activeExecutions = await this.hasActiveExecutions(workflowId);
if (activeExecutions > 0) {
throw new HttpException(
409,
`Cannot delete workflow: it has ${activeExecutions} active execution(s). Please wait for them to complete or cancel them first.`,
);
}
await prisma.workflow.delete({
where: {id: workflowId},
});