Files
SerpentRace/SerpentRace_Backend/dist/Application/Organization/commands/CreateOrganizationCommandHandler.js
T

34 lines
1.5 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CreateOrganizationCommandHandler = void 0;
const OrganizationAggregate_1 = require("../../../Domain/Organization/OrganizationAggregate");
const OrganizationMapper_1 = require("../../DTOs/Mappers/OrganizationMapper");
class CreateOrganizationCommandHandler {
constructor(orgRepo) {
this.orgRepo = orgRepo;
}
async execute(cmd) {
try {
const org = new OrganizationAggregate_1.OrganizationAggregate();
org.name = cmd.name;
org.contactfname = cmd.contactfname;
org.contactlname = cmd.contactlname;
org.contactphone = cmd.contactphone;
org.contactemail = cmd.contactemail;
org.url = cmd.url || null;
org.state = OrganizationAggregate_1.OrganizationState.REGISTERED;
const created = await this.orgRepo.create(org);
return OrganizationMapper_1.OrganizationMapper.toShortDto(created);
}
catch (error) {
if (error instanceof Error) {
if (error.message.includes('duplicate key value violates unique constraint')) {
throw new Error('Organization with this name or contact email already exists');
}
}
throw new Error('Failed to create organization');
}
}
}
exports.CreateOrganizationCommandHandler = CreateOrganizationCommandHandler;
//# sourceMappingURL=CreateOrganizationCommandHandler.js.map