2024-10-27 11:47:13 +01:00
|
|
|
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> {
|
2024-11-07 10:49:34 +01:00
|
|
|
const id = req.params.id;
|
2024-10-27 11:47:13 +01:00
|
|
|
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 starttime = req.body.starttime;
|
|
|
|
const endtime = req.body.endtime;
|
|
|
|
const title = req.body.title;
|
|
|
|
const content = req.body.content;
|
2024-10-28 16:02:56 +01:00
|
|
|
const location = req.body.location;
|
|
|
|
const allDay = req.body.allDay;
|
2024-10-27 11:47:13 +01:00
|
|
|
const typeId = req.body.typeId;
|
|
|
|
|
|
|
|
let createItem: CreateCalendarCommand = {
|
|
|
|
starttime,
|
|
|
|
endtime,
|
|
|
|
title,
|
|
|
|
content,
|
2024-10-28 16:02:56 +01:00
|
|
|
location,
|
|
|
|
allDay,
|
2024-10-27 11:47:13 +01:00
|
|
|
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;
|
2024-12-03 19:29:38 +01:00
|
|
|
const passphrase = req.body.passphrase;
|
2024-10-27 11:47:13 +01:00
|
|
|
|
|
|
|
let createType: CreateCalendarTypeCommand = {
|
|
|
|
type,
|
|
|
|
nscdr,
|
|
|
|
color,
|
2024-12-03 19:29:38 +01:00
|
|
|
passphrase,
|
2024-10-27 11:47:13 +01:00
|
|
|
};
|
|
|
|
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> {
|
2024-10-28 16:02:56 +01:00
|
|
|
const id = req.params.id;
|
2024-10-27 11:47:13 +01:00
|
|
|
const starttime = req.body.starttime;
|
|
|
|
const endtime = req.body.endtime;
|
|
|
|
const title = req.body.title;
|
|
|
|
const content = req.body.content;
|
2024-10-28 16:02:56 +01:00
|
|
|
const location = req.body.location;
|
|
|
|
const allDay = req.body.allDay;
|
2024-10-27 11:47:13 +01:00
|
|
|
const typeId = req.body.typeId;
|
|
|
|
|
|
|
|
let updateItem: UpdateCalendarCommand = {
|
|
|
|
id,
|
|
|
|
starttime,
|
|
|
|
endtime,
|
|
|
|
title,
|
|
|
|
content,
|
2024-10-28 16:02:56 +01:00
|
|
|
location,
|
|
|
|
allDay,
|
2024-10-27 11:47:13 +01:00
|
|
|
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;
|
2024-12-03 19:29:38 +01:00
|
|
|
const passphrase = req.body.passphrase;
|
2024-10-27 11:47:13 +01:00
|
|
|
|
|
|
|
let updateType: UpdateCalendarTypeCommand = {
|
|
|
|
id,
|
|
|
|
type,
|
|
|
|
nscdr,
|
|
|
|
color,
|
2024-12-03 19:29:38 +01:00
|
|
|
passphrase,
|
2024-10-27 11:47:13 +01:00
|
|
|
};
|
|
|
|
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> {
|
2024-10-28 16:02:56 +01:00
|
|
|
const id = req.params.id;
|
2024-10-27 11:47:13 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|