fix(api): guard unmoved deals before pipeline merge delete
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
# Task 5 report
|
||||
Status: DONE
|
||||
- shared build: OK
|
||||
- pipeline-merge.test.ts: 5/5 pass
|
||||
- api typecheck: OK
|
||||
- vue-tsc: see VUE_EXIT in controller log
|
||||
- graphify: attempted (may crash)
|
||||
No commit required for verification-only task.
|
||||
|
||||
## Follow-up fix: final review important findings
|
||||
Status: DONE
|
||||
- I-1: Added in-transaction unmoved-deal count guard before deleting the source pipeline.
|
||||
- I-3: Added 30000ms timeout to the interactive merge transaction.
|
||||
- M-1: Added `@IsIn(['retarget_all'])` validation to `MergePipelineDto.leadFormMode`.
|
||||
- graphify update: OK
|
||||
- `cd apps/api; npx tsx --test test/pipeline-merge.test.ts`: OK, 5/5 pass
|
||||
- `npm run typecheck -w @mento/api`: OK
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
IsArray,
|
||||
IsBoolean,
|
||||
IsDateString,
|
||||
IsIn,
|
||||
IsInt,
|
||||
IsNumber,
|
||||
IsObject,
|
||||
@@ -362,5 +363,6 @@ export class MergePipelineDto {
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@IsIn(['retarget_all'])
|
||||
leadFormMode?: 'retarget_all';
|
||||
}
|
||||
|
||||
@@ -416,11 +416,14 @@ export class PipelinesService {
|
||||
);
|
||||
}
|
||||
|
||||
const targetStagesById = new Map(target.stages.map((stage) => [stage.id, stage]));
|
||||
const targetStagesById = new Map(
|
||||
target.stages.map((stage) => [stage.id, stage]),
|
||||
);
|
||||
let movedDeals = 0;
|
||||
let retargetedLeadForms = 0;
|
||||
|
||||
await this.prisma.$transaction(async (tx) => {
|
||||
await this.prisma.$transaction(
|
||||
async (tx) => {
|
||||
const closedAt = new Date();
|
||||
for (const sourceStage of source.stages) {
|
||||
const targetStageId = dto.stageMap[sourceStage.id];
|
||||
@@ -495,8 +498,19 @@ export class PipelinesService {
|
||||
});
|
||||
}
|
||||
|
||||
await tx.pipeline.delete({ where: { id: source.id } });
|
||||
const remaining = await tx.deal.count({
|
||||
where: { organizationId, pipelineId: source.id },
|
||||
});
|
||||
if (remaining > 0) {
|
||||
throw new BadRequestException(
|
||||
'برخی معاملهها منتقل نشدند؛ ادغام لغو شد.',
|
||||
);
|
||||
}
|
||||
|
||||
await tx.pipeline.delete({ where: { id: source.id } });
|
||||
},
|
||||
{ timeout: 30000 },
|
||||
);
|
||||
|
||||
return {
|
||||
ok: true,
|
||||
|
||||
Reference in New Issue
Block a user