UNPKG

skailan-crm

Version:

Servicio de CRM y gestión de ventas para Skailan

21 lines 977 B
import { Opportunity } from '../../domain/entities/Opportunity'; import { v4 as uuidv4 } from 'uuid'; export class CreateOpportunity { opportunityRepository; leadRepository; constructor(opportunityRepository, leadRepository) { this.opportunityRepository = opportunityRepository; this.leadRepository = leadRepository; } async execute(request) { const { organizationId, leadId, name, amount, probability, closeDate, notes } = request; const lead = await this.leadRepository.findById(leadId, organizationId); if (!lead) { throw new Error('Lead not found.'); } const newOpportunity = new Opportunity(uuidv4(), organizationId, leadId, name, 'Prospecting', // Default stage amount || null, probability || null, closeDate || null, notes || null, new Date(), new Date()); return this.opportunityRepository.save(newOpportunity); } } //# sourceMappingURL=CreateOpportunity.js.map