import { dataSource } from "../data-source"; import { calendarType } from "../entity/calendarType"; import InternalException from "../exceptions/internalException"; import { CreateCalendarTypeCommand, DeleteCalendarTypeCommand, UpdateCalendarTypeCommand } from "./calendarTypeCommand"; export default abstract class CalendarTypeCommandHandler { /** * @description create calendarType * @param CreateCalendarTypeCommand * @returns {Promise} */ static async create(createCalendarType: CreateCalendarTypeCommand): Promise { return await dataSource .createQueryBuilder() .insert() .into(calendarType) .values({ type: createCalendarType.type, nscdr: createCalendarType.nscdr, color: createCalendarType.color, passphrase: createCalendarType.nscdr ? null : createCalendarType.passphrase, }) .execute() .then((result) => { return result.identifiers[0].id; }) .catch((err) => { throw new InternalException("Failed creating calendarType", err); }); } /** * @description update calendarType * @param UpdateCalendarTypeCommand * @returns {Promise} */ static async update(updateCalendarType: UpdateCalendarTypeCommand): Promise { return await dataSource .createQueryBuilder() .update(calendarType) .set({ type: updateCalendarType.type, nscdr: updateCalendarType.nscdr, color: updateCalendarType.color, passphrase: updateCalendarType.nscdr ? null : updateCalendarType.passphrase, }) .where("id = :id", { id: updateCalendarType.id }) .execute() .then(() => {}) .catch((err) => { throw new InternalException("Failed updating award", err); }); } /** * @description delete calendarType * @param DeleteCalendarTypeCommand * @returns {Promise} */ static async delete(deleteCalendarType: DeleteCalendarTypeCommand): Promise { return await dataSource .createQueryBuilder() .delete() .from(calendarType) .where("id = :id", { id: deleteCalendarType.id }) .execute() .then(() => {}) .catch((err) => { throw new InternalException("Failed deleting calendarType", err); }); } }