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

28 lines
1.1 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CreateContactCommandHandler = void 0;
const ContactAggregate_1 = require("../../../Domain/Contact/ContactAggregate");
const ContactMapper_1 = require("../../DTOs/Mappers/ContactMapper");
class CreateContactCommandHandler {
constructor(contactRepo) {
this.contactRepo = contactRepo;
}
async execute(cmd) {
try {
const contact = new ContactAggregate_1.ContactAggregate();
contact.name = cmd.name;
contact.email = cmd.email;
contact.userid = cmd.userid || null;
contact.type = cmd.type;
contact.txt = cmd.txt;
contact.state = ContactAggregate_1.ContactState.ACTIVE;
const created = await this.contactRepo.create(contact);
return ContactMapper_1.ContactMapper.toShortDto(created);
}
catch (error) {
throw new Error('Failed to create contact');
}
}
}
exports.CreateContactCommandHandler = CreateContactCommandHandler;
//# sourceMappingURL=CreateContactCommandHandler.js.map