Files
SerpentRace/SerpentRace_Backend/dist/Application/Contact/commands/UpdateContactCommandHandler.js
T

41 lines
1.5 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.UpdateContactCommandHandler = void 0;
const ContactMapper_1 = require("../../DTOs/Mappers/ContactMapper");
class UpdateContactCommandHandler {
constructor(contactRepo) {
this.contactRepo = contactRepo;
}
async execute(cmd) {
try {
const existingContact = await this.contactRepo.findById(cmd.id);
if (!existingContact) {
throw new Error('Contact not found');
}
const updateData = {};
if (cmd.adminResponse !== undefined) {
updateData.adminResponse = cmd.adminResponse;
updateData.responseDate = new Date();
}
if (cmd.state !== undefined) {
updateData.state = cmd.state;
}
if (cmd.respondedBy !== undefined) {
updateData.respondedBy = cmd.respondedBy;
}
const updated = await this.contactRepo.update(cmd.id, updateData);
if (!updated) {
throw new Error('Failed to update contact');
}
return ContactMapper_1.ContactMapper.toDetailDto(updated);
}
catch (error) {
if (error instanceof Error && error.message === 'Contact not found') {
throw error;
}
throw new Error('Failed to update contact');
}
}
}
exports.UpdateContactCommandHandler = UpdateContactCommandHandler;
//# sourceMappingURL=UpdateContactCommandHandler.js.map