Helpers.ts 438 Bytes
Newer Older
Hanadi's avatar
Hanadi committed
1
2
3
4
5
6
7
8
9
10
11
12
import {Exception} from "./Exception";
import {ExceptionCode} from "./ExceptionCode";

export function validateRequiredFields(obj: any, fields: string[], className?: string) {
    fields.forEach(field => {
        if (!obj.hasOwnProperty(field))
            throw new Exception(
                ExceptionCode.MISSING_REQUIRED_FIELD,
                `Missing field ${field}` + (className ? ` from ${className}` : '')
            )
    })
}