Add hiding dearrow submissions in ban code

This commit is contained in:
Ajay
2023-07-05 01:23:48 -04:00
parent 5f80562772
commit 8b418c8851
7 changed files with 158 additions and 22 deletions

View File

@@ -1,5 +1,5 @@
import { Request } from "express";
import { ActionType, SegmentUUID, Category } from "../types/segments.model";
import { ActionType, SegmentUUID, Category, DeArrowType } from "../types/segments.model";
import { config } from "../config";
type fn = (req: Request, fallback: any) => any[];
@@ -11,15 +11,21 @@ const syntaxErrorWrapper = (fn: fn, req: Request, fallback: any) => {
}
};
const getCategories = (req: Request, fallback: Category[] ): string[] | Category[] =>
req.query.categories
? JSON.parse(req.query.categories as string)
: req.query.category
? Array.isArray(req.query.category)
? req.query.category
: [req.query.category]
const getQueryList = <T>(req: Request, fallback: T[], param: string, paramPlural: string): string[] | T[] =>
req.query[paramPlural]
? JSON.parse(req.query[paramPlural] as string)
: req.query[param]
? Array.isArray(req.query[param])
? req.query[param]
: [req.query[param]]
: fallback;
const getCategories = (req: Request, fallback: Category[] ): string[] | Category[] =>
getQueryList(req, fallback, "category", "categories");
const getDeArrowTypes = (req: Request, fallback: DeArrowType[] ): string[] | DeArrowType[] =>
getQueryList(req, fallback, "deArrowType", "deArrowTypes");
const validateString = (array: any[]): any[] => {
if (!Array.isArray(array)) return undefined;
return array
@@ -71,6 +77,11 @@ export const parseActionTypes = (req: Request, fallback: ActionType[]): ActionTy
return actionTypes ? validateString(actionTypes) : undefined;
};
export const parseDeArrowTypes = (req: Request, fallback: DeArrowType[]): DeArrowType[] => {
const deArrowTypes = syntaxErrorWrapper(getDeArrowTypes, req, fallback);
return deArrowTypes ? validateString(deArrowTypes) : undefined;
};
export const parseRequiredSegments = (req: Request): SegmentUUID[] | undefined =>
syntaxErrorWrapper(getRequiredSegments, req, []); // never fall back