ff-admin-server/src/command/calendarTypeCommandHandler.ts

71 lines
2.1 KiB
TypeScript
Raw Normal View History

2024-10-27 10:47:13 +00:00
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<number>}
*/
static async create(createCalendarType: CreateCalendarTypeCommand): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(calendarType)
.values({
type: createCalendarType.type,
nscdr: createCalendarType.nscdr,
color: createCalendarType.color,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed creating calendarType", err);
});
}
/**
* @description update calendarType
* @param UpdateCalendarTypeCommand
* @returns {Promise<void>}
*/
static async update(updateCalendarType: UpdateCalendarTypeCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.update(calendarType)
.set({
type: updateCalendarType.type,
nscdr: updateCalendarType.nscdr,
color: updateCalendarType.color,
})
.where("id = :id", { id: updateCalendarType.id })
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed updating award", err);
});
}
/**
* @description delete calendarType
* @param DeleteCalendarTypeCommand
* @returns {Promise<void>}
*/
static async delete(deleteCalendarType: DeleteCalendarTypeCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.delete()
.from(calendarType)
.where("id = :id", { id: deleteCalendarType.id })
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed deleting calendarType", err);
});
}
}