44 lines
1.6 KiB
JavaScript
44 lines
1.6 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.DeleteContactCommandHandler = void 0;
|
|
const Logger_1 = require("../../Services/Logger");
|
|
class DeleteContactCommandHandler {
|
|
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');
|
|
}
|
|
if (cmd.hard) {
|
|
// Permanent delete
|
|
await this.contactRepo.delete(cmd.id);
|
|
(0, Logger_1.logRequest)('Contact hard deleted', undefined, undefined, {
|
|
contactId: cmd.id,
|
|
contactEmail: existingContact.email,
|
|
deleteType: 'hard'
|
|
});
|
|
}
|
|
else {
|
|
// Soft delete (default)
|
|
await this.contactRepo.softDelete(cmd.id);
|
|
(0, Logger_1.logRequest)('Contact soft deleted', undefined, undefined, {
|
|
contactId: cmd.id,
|
|
contactEmail: existingContact.email,
|
|
deleteType: 'soft'
|
|
});
|
|
}
|
|
return true;
|
|
}
|
|
catch (error) {
|
|
if (error instanceof Error && error.message === 'Contact not found') {
|
|
throw error;
|
|
}
|
|
throw new Error('Failed to delete contact');
|
|
}
|
|
}
|
|
}
|
|
exports.DeleteContactCommandHandler = DeleteContactCommandHandler;
|
|
//# sourceMappingURL=DeleteContactCommandHandler.js.map
|