diff --git a/src/routes/getLockReason.ts b/src/routes/getLockReason.ts index 30d1330..718f54f 100644 --- a/src/routes/getLockReason.ts +++ b/src/routes/getLockReason.ts @@ -4,6 +4,13 @@ import {Request, Response} from "express"; import { Category, VideoID } from "../types/segments.model"; import {config} from "../config"; +const possibleCategoryList = config.categoryList; +interface lockArray { + category: Category; + locked: number, + reason: string +} + export async function getLockCategories(req: Request, res: Response): Promise { const videoID = req.query.videoID as VideoID; let categories: Category[] = []; @@ -14,13 +21,15 @@ export async function getLockCategories(req: Request, res: Response): Promise possibleCategoryList.includes(x)); if (videoID == undefined) { //invalid request @@ -32,23 +41,28 @@ export async function getLockCategories(req: Request, res: Response): Promise config.categoryList.includes(reqCategory)); - for (const noLock of notLocked) { + // add empty locks for categories requested but not locked + const noLockCategories = searchCategories.filter(x => !lockedCategories.includes(x)); + for (const noLock of noLockCategories) { locks.push({ category: noLock, locked: 0, reason: "" - }); + } as lockArray); } - const filtered = locks.filter(lock => categories.includes(lock.category)); - return res.send(...filtered, ...notLocked ); + // return real and fake locks that were requested + const filtered = locks.filter(lock => searchCategories.includes(lock.category)); + return res.send(filtered); } catch (err) { Logger.error(err as string); return res.sendStatus(500);