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

@ -101,11 +101,13 @@ export async function createCalendarType(req: Request, res: Response): Promise<a
const type = req.body.type;
const nscdr = req.body.nscdr;
const color = req.body.color;
const passphrase = req.body.passphrase;
let createType: CreateCalendarTypeCommand = {
type,
nscdr,
color,
passphrase,
};
let id = await CalendarTypeCommandHandler.create(createType);
@ -154,12 +156,14 @@ export async function updateCalendarType(req: Request, res: Response): Promise<a
const type = req.body.type;
const nscdr = req.body.nscdr;
const color = req.body.color;
const passphrase = req.body.passphrase;
let updateType: UpdateCalendarTypeCommand = {
id,
type,
nscdr,
color,
passphrase,
};
await CalendarTypeCommandHandler.update(updateType);

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