calender crud operations
This commit is contained in:
parent
e7b8257336
commit
bf701163d6
18 changed files with 703 additions and 0 deletions
22
src/command/calendarCommand.ts
Normal file
22
src/command/calendarCommand.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
export interface CreateCalendarCommand {
|
||||
date: Date;
|
||||
starttime: Date;
|
||||
endtime: Date;
|
||||
title: string;
|
||||
content: string;
|
||||
typeId: number;
|
||||
}
|
||||
|
||||
export interface UpdateCalendarCommand {
|
||||
id: number;
|
||||
date: Date;
|
||||
starttime: Date;
|
||||
endtime: Date;
|
||||
title: string;
|
||||
content: string;
|
||||
typeId: number;
|
||||
}
|
||||
|
||||
export interface DeleteCalendarCommand {
|
||||
id: number;
|
||||
}
|
85
src/command/calendarCommandHandler.ts
Normal file
85
src/command/calendarCommandHandler.ts
Normal file
|
@ -0,0 +1,85 @@
|
|||
import { dataSource } from "../data-source";
|
||||
import { calendar } from "../entity/calendar";
|
||||
import { calendarType } from "../entity/calendarType";
|
||||
import InternalException from "../exceptions/internalException";
|
||||
import { CreateCalendarCommand, DeleteCalendarCommand, UpdateCalendarCommand } from "./calendarCommand";
|
||||
|
||||
export default abstract class CalendarCommandHandler {
|
||||
/**
|
||||
* @description create calendar
|
||||
* @param CreateCalendarCommand
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
static async create(createCalendar: CreateCalendarCommand): Promise<number> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(calendar)
|
||||
.values({
|
||||
date: createCalendar.date,
|
||||
starttime: createCalendar.starttime,
|
||||
endtime: createCalendar.endtime,
|
||||
title: createCalendar.title,
|
||||
content: createCalendar.content,
|
||||
type: await dataSource
|
||||
.getRepository(calendarType)
|
||||
.createQueryBuilder("type")
|
||||
.where("id = :id", { id: createCalendar.typeId })
|
||||
.getOneOrFail(),
|
||||
})
|
||||
.execute()
|
||||
.then((result) => {
|
||||
return result.identifiers[0].id;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new InternalException("Failed creating calendar", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description update calendar
|
||||
* @param UpdateCalendarCommand
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async update(updateCalendar: UpdateCalendarCommand): Promise<void> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.update(calendar)
|
||||
.set({
|
||||
date: updateCalendar.date,
|
||||
starttime: updateCalendar.starttime,
|
||||
endtime: updateCalendar.endtime,
|
||||
title: updateCalendar.title,
|
||||
content: updateCalendar.content,
|
||||
type: await dataSource
|
||||
.getRepository(calendarType)
|
||||
.createQueryBuilder("type")
|
||||
.where("id = :id", { id: updateCalendar.typeId })
|
||||
.getOneOrFail(),
|
||||
})
|
||||
.where("id = :id", { id: updateCalendar.id })
|
||||
.execute()
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw new InternalException("Failed updating award", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description delete calendar
|
||||
* @param DeleteCalendarCommand
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async delete(deleteCalendar: DeleteCalendarCommand): Promise<void> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(calendar)
|
||||
.where("id = :id", { id: deleteCalendar.id })
|
||||
.execute()
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw new InternalException("Failed deleting calendar", err);
|
||||
});
|
||||
}
|
||||
}
|
16
src/command/calendarTypeCommand.ts
Normal file
16
src/command/calendarTypeCommand.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
export interface CreateCalendarTypeCommand {
|
||||
type: string;
|
||||
nscdr: boolean;
|
||||
color: string;
|
||||
}
|
||||
|
||||
export interface UpdateCalendarTypeCommand {
|
||||
id: number;
|
||||
type: string;
|
||||
nscdr: boolean;
|
||||
color: string;
|
||||
}
|
||||
|
||||
export interface DeleteCalendarTypeCommand {
|
||||
id: number;
|
||||
}
|
70
src/command/calendarTypeCommandHandler.ts
Normal file
70
src/command/calendarTypeCommandHandler.ts
Normal file
|
@ -0,0 +1,70 @@
|
|||
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);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue