skailan-contacts
Version:
Servicio de gestión de contactos para Skailan
16 lines • 953 B
JavaScript
export class UpdateContact {
contactRepository;
constructor(contactRepository) {
this.contactRepository = contactRepository;
}
async execute(request) {
const { id, organizationId, ...updates } = request;
const existingContact = await this.contactRepository.findById(id, organizationId);
if (!existingContact) {
throw new Error('Contact not found.');
}
existingContact.updateInfo(updates.name !== undefined ? updates.name : existingContact.name, updates.email !== undefined ? updates.email : existingContact.email, updates.phone !== undefined ? updates.phone : existingContact.phone, updates.profilePictureUrl !== undefined ? updates.profilePictureUrl : existingContact.profilePictureUrl, updates.metadata !== undefined ? updates.metadata : existingContact.metadata);
return this.contactRepository.save(existingContact);
}
}
//# sourceMappingURL=UpdateContact.js.map