29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
|
import { Request, Response } from "express";
|
||
|
import BadRequestException from "../exceptions/badRequestException";
|
||
|
|
||
|
export default class ParamaterPassCheckHelper {
|
||
|
static requiredIncluded(testfor: Array<string>, obj: object) {
|
||
|
let result = testfor.every((key) => Object.keys(obj).includes(key));
|
||
|
if (!result) throw new BadRequestException(`not all required parameters included: ${testfor.join(",")}`);
|
||
|
}
|
||
|
|
||
|
static forbiddenIncluded(testfor: Array<string>, obj: object) {
|
||
|
let result = testfor.some((key) => Object.keys(obj).includes(key));
|
||
|
if (!result) throw new BadRequestException(`PPC: forbidden parameters included: ${testfor.join(",")}`);
|
||
|
}
|
||
|
|
||
|
static requiredIncludedMiddleware(testfor: Array<string>): (req: Request, res: Response, next: Function) => void {
|
||
|
return (req: Request, res: Response, next: Function) => {
|
||
|
this.requiredIncluded(testfor, req.body);
|
||
|
next();
|
||
|
};
|
||
|
}
|
||
|
|
||
|
static forbiddenIncludedMiddleware(testfor: Array<string>): (req: Request, res: Response, next: Function) => void {
|
||
|
return (req: Request, res: Response, next: Function) => {
|
||
|
this.requiredIncluded(testfor, req.body);
|
||
|
next();
|
||
|
};
|
||
|
}
|
||
|
}
|