diff --git a/src/Controller.ts b/src/Controller.ts index 9304438..d9ab8ab 100644 --- a/src/Controller.ts +++ b/src/Controller.ts @@ -2,6 +2,7 @@ import {RequestHandler, Router} from "express"; import {PathParams} from "express-serve-static-core"; import config from "config"; import Logger from "./Logger"; +import Validator from "./db/Validator"; export default abstract class Controller { private static readonly routes: { [p: string]: string } = {}; @@ -115,6 +116,14 @@ export default abstract class Controller { } } } + + protected async validate(validationMap: { [p: string]: Validator }, body: any): Promise { + for (const p in validationMap) { + if (validationMap.hasOwnProperty(p)) { + await validationMap[p].execute(p, body[p], false); + } + } + } } export type RouteParams = { [p: string]: string } | string[] | string | number; \ No newline at end of file