calender crud operations
This commit is contained in:
parent
e7b8257336
commit
bf701163d6
18 changed files with 703 additions and 0 deletions
197
src/controller/admin/calendarController.ts
Normal file
197
src/controller/admin/calendarController.ts
Normal file
|
@ -0,0 +1,197 @@
|
|||
import { Request, Response } from "express";
|
||||
import CalendarService from "../../service/calendarService";
|
||||
import CalendarFactory from "../../factory/admin/calendar";
|
||||
import CalendarTypeService from "../../service/calendarTypeService";
|
||||
import CalendarTypeFactory from "../../factory/admin/calendarType";
|
||||
import { CreateCalendarCommand, DeleteCalendarCommand, UpdateCalendarCommand } from "../../command/calendarCommand";
|
||||
import CalendarCommandHandler from "../../command/calendarCommandHandler";
|
||||
import {
|
||||
CreateCalendarTypeCommand,
|
||||
DeleteCalendarTypeCommand,
|
||||
UpdateCalendarTypeCommand,
|
||||
} from "../../command/calendarTypeCommand";
|
||||
import CalendarTypeCommandHandler from "../../command/calendarTypeCommandHandler";
|
||||
|
||||
/**
|
||||
* @description get all calendar items
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function getAllCalendarItems(req: Request, res: Response): Promise<any> {
|
||||
let items = await CalendarService.getAll();
|
||||
|
||||
res.json(CalendarFactory.mapToBase(items));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get calendar item by id
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function getCalendarItemById(req: Request, res: Response): Promise<any> {
|
||||
const id = parseInt(req.params.id);
|
||||
let item = await CalendarService.getById(id);
|
||||
|
||||
res.json(CalendarFactory.mapToSingle(item));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get all calendar types
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function getAllCalendarTypes(req: Request, res: Response): Promise<any> {
|
||||
let types = await CalendarTypeService.getAll();
|
||||
|
||||
res.json(CalendarTypeFactory.mapToBase(types));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get calendar type by id
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function getCalendarTypeById(req: Request, res: Response): Promise<any> {
|
||||
const id = parseInt(req.params.id);
|
||||
let type = await CalendarTypeService.getById(id);
|
||||
|
||||
res.json(CalendarTypeFactory.mapToSingle(type));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description create calendar item
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function createCalendarItem(req: Request, res: Response): Promise<any> {
|
||||
const date = req.body.date;
|
||||
const starttime = req.body.starttime;
|
||||
const endtime = req.body.endtime;
|
||||
const title = req.body.title;
|
||||
const content = req.body.content;
|
||||
const typeId = req.body.typeId;
|
||||
|
||||
let createItem: CreateCalendarCommand = {
|
||||
date,
|
||||
starttime,
|
||||
endtime,
|
||||
title,
|
||||
content,
|
||||
typeId,
|
||||
};
|
||||
let id = await CalendarCommandHandler.create(createItem);
|
||||
|
||||
res.send(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description create calendar type
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function createCalendarType(req: Request, res: Response): Promise<any> {
|
||||
const type = req.body.type;
|
||||
const nscdr = req.body.nscdr;
|
||||
const color = req.body.color;
|
||||
|
||||
let createType: CreateCalendarTypeCommand = {
|
||||
type,
|
||||
nscdr,
|
||||
color,
|
||||
};
|
||||
let id = await CalendarTypeCommandHandler.create(createType);
|
||||
|
||||
res.send(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description update calendar item
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function updateCalendarItem(req: Request, res: Response): Promise<any> {
|
||||
const id = parseInt(req.params.id);
|
||||
const date = req.body.date;
|
||||
const starttime = req.body.starttime;
|
||||
const endtime = req.body.endtime;
|
||||
const title = req.body.title;
|
||||
const content = req.body.content;
|
||||
const typeId = req.body.typeId;
|
||||
|
||||
let updateItem: UpdateCalendarCommand = {
|
||||
id,
|
||||
date,
|
||||
starttime,
|
||||
endtime,
|
||||
title,
|
||||
content,
|
||||
typeId,
|
||||
};
|
||||
await CalendarCommandHandler.update(updateItem);
|
||||
|
||||
res.sendStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description update calendar type
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function updateCalendarType(req: Request, res: Response): Promise<any> {
|
||||
const id = parseInt(req.params.id);
|
||||
const type = req.body.type;
|
||||
const nscdr = req.body.nscdr;
|
||||
const color = req.body.color;
|
||||
|
||||
let updateType: UpdateCalendarTypeCommand = {
|
||||
id,
|
||||
type,
|
||||
nscdr,
|
||||
color,
|
||||
};
|
||||
await CalendarTypeCommandHandler.update(updateType);
|
||||
|
||||
res.sendStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description delete calendar item
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function deleteCalendarItem(req: Request, res: Response): Promise<any> {
|
||||
const id = parseInt(req.params.id);
|
||||
|
||||
let deleteItem: DeleteCalendarCommand = {
|
||||
id,
|
||||
};
|
||||
await CalendarCommandHandler.delete(deleteItem);
|
||||
|
||||
res.sendStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description delete calendar type
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function deleteCalendarType(req: Request, res: Response): Promise<any> {
|
||||
const id = parseInt(req.params.id);
|
||||
|
||||
let deleteType: DeleteCalendarTypeCommand = {
|
||||
id,
|
||||
};
|
||||
await CalendarTypeCommandHandler.delete(deleteType);
|
||||
|
||||
res.sendStatus(204);
|
||||
}
|
25
src/controller/publicController.ts
Normal file
25
src/controller/publicController.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import { Request, Response } from "express";
|
||||
import CalendarFactory from "../factory/admin/calendar";
|
||||
import CalendarService from "../service/calendarService";
|
||||
import CalendarTypeService from "../service/calendarTypeService";
|
||||
import { calendar } from "../entity/calendar";
|
||||
|
||||
/**
|
||||
* @description get all calendar items by types or nscdr
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function getCalendarItemsByTypes(req: Request, res: Response): Promise<any> {
|
||||
let types = Array.isArray(req.query.types) ? req.query.types : [req.query.types];
|
||||
|
||||
let items: Array<calendar> = [];
|
||||
if (types.length == 0) {
|
||||
let typeIds = await CalendarTypeService.getByTypes(types as Array<string>);
|
||||
items = await CalendarService.getByTypes(typeIds.map((t) => t.id));
|
||||
} else {
|
||||
items = await CalendarService.getByTypeNSCDR();
|
||||
}
|
||||
|
||||
res.json(CalendarFactory.mapToBase(items));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue