skailan-conversations
Version:
Servicio de conversaciones y mensajería para Skailan
28 lines • 1.28 kB
JavaScript
export class AddTagToConversation {
conversationTagRepository;
conversationRepository;
tagRepository;
constructor(conversationTagRepository, conversationRepository, tagRepository) {
this.conversationTagRepository = conversationTagRepository;
this.conversationRepository = conversationRepository;
this.tagRepository = tagRepository;
}
async execute(request) {
const { organizationId, conversationId, tagId } = request;
const conversation = await this.conversationRepository.findById(conversationId, organizationId);
if (!conversation) {
throw new Error('Conversation not found.');
}
const tag = await this.tagRepository.findById(tagId, organizationId);
if (!tag) {
throw new Error('Tag not found.');
}
// Check if already tagged
const existingTags = await this.conversationTagRepository.findTagsByConversation(conversationId, organizationId);
if (existingTags.some(ct => ct.tagId === tagId)) {
throw new Error('Conversation already has this tag.');
}
return this.conversationTagRepository.addTagToConversation(conversationId, tagId, organizationId);
}
}
//# sourceMappingURL=AddTagToConversation.js.map