Skip to content
Snippets Groups Projects
Commit d2ae8ec4 authored by Rafael László's avatar Rafael László :speech_balloon:
Browse files

validateFields function added

parent 8ea236f0
Branches
No related tags found
2 merge requests!27refresh dev branch,!26Feature/refactor
Pipeline #5627 passed
import { Request } from "express";
import { ValidationError } from "./ValidationError";
interface IValidateFields {
fields: {
name: string;
required: boolean;
}[];
reqBody: Request["body"];
}
export function validateFields({ fields, reqBody }: IValidateFields) {
fields.forEach((field) => {
const value = reqBody[field.name];
if (field.required && !value) {
throw new ValidationError(400, `Field: {${field.name}} is required!`);
}
});
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment