From e9b29f8acf594c17bcab5c81bbf308dddf1972c8 Mon Sep 17 00:00:00 2001 From: Julian Krauser Date: Tue, 24 Dec 2024 14:06:48 +0100 Subject: [PATCH] extend calendar link --- src/controller/publicController.ts | 6 +++++- src/service/calendarService.ts | 12 +++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/controller/publicController.ts b/src/controller/publicController.ts index 8c627fc..15c5d73 100644 --- a/src/controller/publicController.ts +++ b/src/controller/publicController.ts @@ -16,6 +16,7 @@ import CalendarFactory from "../factory/admin/calendar"; */ export async function getCalendarItemsByTypes(req: Request, res: Response): Promise { let types = Array.isArray(req.query.types) ? req.query.types : [req.query.types]; + let nscdr = req.query.nscdr == "true"; let output = (req.query.output as "ics" | "json") ?? "ics"; if (output != "ics" && output != "json") { @@ -33,7 +34,10 @@ export async function getCalendarItemsByTypes(req: Request, res: Response): Prom ti.passphrase == "" || ti.passphrase == (types as Array).find((t) => t.includes(ti.type)).split(":")[1] ); - items = await CalendarService.getByTypes(typeIds.map((t) => t.id)); + items = await CalendarService.getByTypes( + typeIds.map((t) => t.id), + nscdr + ); } else { items = await CalendarService.getByTypeNSCDR(); } diff --git a/src/service/calendarService.ts b/src/service/calendarService.ts index 48c771d..5bbf4f4 100644 --- a/src/service/calendarService.ts +++ b/src/service/calendarService.ts @@ -44,12 +44,18 @@ export default abstract class CalendarService { * @description get calendar by types * @returns {Promise>} */ - static async getByTypes(types: Array): Promise> { - return await dataSource + static async getByTypes(types: Array, addNscdr: boolean = false): Promise> { + const query = dataSource .getRepository(calendar) .createQueryBuilder("calendar") .leftJoinAndSelect("calendar.type", "type") - .where("type.id IN (:...types)", { types: types }) + .where("type.id IN (:...types)", { types: types }); + + if (addNscdr) { + query.orWhere("type.nscdr = :nscdr", { nscdr: true }); + } + + return await query .getMany() .then((res) => { return res;