secure type with passphrase

This commit is contained in:
Julian Krauser 2024-12-03 19:29:38 +01:00
parent 597feef9ef
commit 8f49533fcb
9 changed files with 44 additions and 2 deletions

View file

@ -9,6 +9,7 @@ import CalendarFactory from "../factory/admin/calendar";
/**
* @description get all calendar items by types or nscdr
* @summary passphrase is passed as value pair like `type:passphrase`
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
@ -22,8 +23,14 @@ export async function getCalendarItemsByTypes(req: Request, res: Response): Prom
}
let items: Array<calendar> = [];
if (types.length == 0) {
let typeIds = await CalendarTypeService.getByTypes(types as Array<string>);
if (types.length != 0) {
let typeIds = await CalendarTypeService.getByTypes((types as Array<string>).map((t) => t.split(":")[0]));
typeIds = typeIds.filter(
(ti) =>
ti.passphrase == null ||
ti.passphrase == "" ||
ti.passphrase == (types as Array<string>).find((t) => t.includes(ti.type)).split(":")[1]
);
items = await CalendarService.getByTypes(typeIds.map((t) => t.id));
} else {
items = await CalendarService.getByTypeNSCDR();