skailan-crm
Version:
Servicio de CRM y gestión de ventas para Skailan
31 lines • 1.44 kB
JavaScript
import { Activity } from '../../domain/entities/Activity';
import { v4 as uuidv4 } from 'uuid';
export class CreateActivity {
activityRepository;
leadRepository;
opportunityRepository;
constructor(activityRepository, leadRepository, opportunityRepository) {
this.activityRepository = activityRepository;
this.leadRepository = leadRepository;
this.opportunityRepository = opportunityRepository;
}
async execute(request) {
const { organizationId, type, description, date, relatedLeadId, relatedOpportunityId, assignedToUserId } = request;
if (relatedLeadId) {
const lead = await this.leadRepository.findById(relatedLeadId, organizationId);
if (!lead) {
throw new Error('Related Lead not found.');
}
}
if (relatedOpportunityId) {
const opportunity = await this.opportunityRepository.findById(relatedOpportunityId, organizationId);
if (!opportunity) {
throw new Error('Related Opportunity not found.');
}
}
const newActivity = new Activity(uuidv4(), organizationId, type, description, date, relatedLeadId || null, relatedOpportunityId || null, assignedToUserId || null, 'Pending', // Default status
new Date(), new Date());
return this.activityRepository.save(newActivity);
}
}
//# sourceMappingURL=CreateActivity.js.map