ff-admin-server/src/controller/publicController.ts

25 lines
957 B
TypeScript

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));
}