72 lines
2.3 KiB
TypeScript
72 lines
2.3 KiB
TypeScript
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,
|
|
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<void>}
|
|
*/
|
|
static async update(updateCalendarType: UpdateCalendarTypeCommand): Promise<void> {
|
|
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<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);
|
|
});
|
|
}
|
|
}
|