extend calendar link

This commit is contained in:
Julian Krauser 2024-12-24 14:06:48 +01:00
parent 020ae4a939
commit e9b29f8acf
2 changed files with 14 additions and 4 deletions

View file

@ -16,6 +16,7 @@ import CalendarFactory from "../factory/admin/calendar";
*/ */
export async function getCalendarItemsByTypes(req: Request, res: Response): Promise<any> { export async function getCalendarItemsByTypes(req: Request, res: Response): Promise<any> {
let types = Array.isArray(req.query.types) ? req.query.types : [req.query.types]; 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"; let output = (req.query.output as "ics" | "json") ?? "ics";
if (output != "ics" && output != "json") { if (output != "ics" && output != "json") {
@ -33,7 +34,10 @@ export async function getCalendarItemsByTypes(req: Request, res: Response): Prom
ti.passphrase == "" || ti.passphrase == "" ||
ti.passphrase == (types as Array<string>).find((t) => t.includes(ti.type)).split(":")[1] ti.passphrase == (types as Array<string>).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 { } else {
items = await CalendarService.getByTypeNSCDR(); items = await CalendarService.getByTypeNSCDR();
} }

View file

@ -44,12 +44,18 @@ export default abstract class CalendarService {
* @description get calendar by types * @description get calendar by types
* @returns {Promise<Array<calendar>>} * @returns {Promise<Array<calendar>>}
*/ */
static async getByTypes(types: Array<number>): Promise<Array<calendar>> { static async getByTypes(types: Array<number>, addNscdr: boolean = false): Promise<Array<calendar>> {
return await dataSource const query = dataSource
.getRepository(calendar) .getRepository(calendar)
.createQueryBuilder("calendar") .createQueryBuilder("calendar")
.leftJoinAndSelect("calendar.type", "type") .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() .getMany()
.then((res) => { .then((res) => {
return res; return res;