Deals import: imported pipelines keep only Didar stages; remove unused default stages

This commit is contained in:
2026-10-06 16:58:25 +03:30
parent 2a2728e5ee
commit 3de2d0fa67
2 changed files with 71 additions and 23 deletions
+19 -10
View File
@@ -15,7 +15,7 @@ import { asCustomFields } from '../common/custom-fields';
import { type Actor, dealAccessWhere } from '../common/record-scope';
import { decimalToBase, loadOrgRates } from '../common/currency';
const DEFAULT_STAGES = [
export const DEFAULT_STAGES = [
{ name: 'سرنخ', isWon: false, isLost: false },
{ name: 'تماس اول', isWon: false, isLost: false },
{ name: 'پیشنهاد', isWon: false, isLost: false },
@@ -107,21 +107,30 @@ export class PipelinesService {
return rows.map((row) => this.toPipelineDto(row));
}
async create(organizationId: string, name: string): Promise<PipelineDto> {
async create(
organizationId: string,
name: string,
opts: { withDefaultStages?: boolean } = {},
): Promise<PipelineDto> {
await this.ensureDefaultPipeline(organizationId);
const withDefaults = opts.withDefaultStages ?? true;
const created = await this.prisma.pipeline.create({
data: {
organizationId,
name: name.trim(),
isDefault: false,
stages: {
create: DEFAULT_STAGES.map((s, index) => ({
name: s.name,
position: index,
isWon: s.isWon,
isLost: s.isLost,
})),
},
...(withDefaults
? {
stages: {
create: DEFAULT_STAGES.map((s, index) => ({
name: s.name,
position: index,
isWon: s.isWon,
isLost: s.isLost,
})),
},
}
: {}),
},
include: { stages: { orderBy: { position: 'asc' } } },
});