All files / src/database/seeds/mdm status-reason.seed.ts

0% Statements 0/10
0% Branches 0/4
0% Functions 0/2
0% Lines 0/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88                                                                                                                                                                               
import { Injectable } from '@nestjs/common';
import { StatusReasonService } from '../../../domains/mdm/application/services/status-reason.service';
 
@Injectable()
export class StatusReasonSeed {
  constructor(private readonly service: StatusReasonService) {}
 
  async seed(): Promise<void> {
    // 1. Statuses
    await this.service.bulkUpsertStatuses([
      {
        statusCode: 'LEAD_NEW',
        statusName: 'New Lead',
        entityTypeKey: 'lead',
        statusClass: 'initial',
        allowedTransitionsTo: ['LEAD_CONTACTED', 'LEAD_QUALIFIED', 'LEAD_LOST'],
        active: true,
      },
      {
        statusCode: 'LEAD_CONTACTED',
        statusName: 'Contacted',
        entityTypeKey: 'lead',
        statusClass: 'intermediate',
        allowedTransitionsTo: ['LEAD_QUALIFIED', 'LEAD_LOST'],
        active: true,
      },
      {
        statusCode: 'LEAD_LOST',
        statusName: 'Lead Lost',
        entityTypeKey: 'lead',
        statusClass: 'terminal',
        requiresReason: true,
        allowedTransitionsTo: [],
        active: true,
      },
    ]);
 
    // 2. Priorities
    await this.service.bulkUpsertPriorities([
      {
        priorityCode: 'CRITICAL',
        priorityName: 'Critical Priority',
        entityTypeKey: 'task',
        priorityLevel: 1,
        slaHours: 4,
        active: true,
      },
      {
        priorityCode: 'HIGH',
        priorityName: 'High Priority',
        entityTypeKey: 'task',
        priorityLevel: 2,
        slaHours: 24,
        active: true,
      },
    ]);
 
    // 3. Reason Groups
    await this.service.bulkUpsertReasonGroups([
      {
        groupCode: 'LEAD_LOST_REASON',
        groupName: 'Lead Lost Reason',
        entityTypeKey: 'lead',
        groupCategory: 'loss',
        active: true,
      },
    ]);
 
    // 4. Reason Definitions
    await this.service.bulkUpsertReasons([
      {
        reasonCode: 'COMPETITOR_CHOSEN',
        reasonName: 'Chose Competitor',
        groupCode: 'LEAD_LOST_REASON',
        entityTypeKey: 'lead',
        active: true,
      },
      {
        reasonCode: 'BUDGET_CONSTRAINTS',
        reasonName: 'Budget constraints',
        groupCode: 'LEAD_LOST_REASON',
        entityTypeKey: 'lead',
        active: true,
      },
    ]);
  }
}