UNPKG

skailan-contacts

Version:

Servicio de gestión de contactos para Skailan

34 lines 1.35 kB
import { Tag } from '../../domain/entities/Tag'; import { v4 as uuidv4 } from 'uuid'; export class CreateTag { tagRepository; constructor(tagRepository) { this.tagRepository = tagRepository; } async execute(request) { try { const { organizationId, name } = request; // Validate required fields if (!organizationId) { throw new Error('Organization ID is required'); } if (!name || name.trim().length === 0) { throw new Error('Tag name is required'); } if (name.length > 50) { throw new Error('Tag name must be less than 50 characters'); } const trimmedName = name.trim(); const existingTag = await this.tagRepository.findByName(trimmedName, organizationId); if (existingTag) { throw new Error('Tag with this name already exists for this organization.'); } const newTag = new Tag(uuidv4(), organizationId, trimmedName, new Date(), new Date()); return await this.tagRepository.save(newTag); } catch (error) { throw new Error(`Error creating tag: ${error instanceof Error ? error.message : 'Unknown error'}`); } } } //# sourceMappingURL=CreateTag.js.map