forked from Yara724/api
Validation for prices and objection
This commit is contained in:
24
src/common/validators/has-objection-entries.validator.ts
Normal file
24
src/common/validators/has-objection-entries.validator.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import {
|
||||
ValidationArguments,
|
||||
ValidatorConstraint,
|
||||
ValidatorConstraintInterface,
|
||||
} from "class-validator";
|
||||
|
||||
@ValidatorConstraint({ name: "hasObjectionEntries", async: false })
|
||||
export class HasObjectionEntriesConstraint
|
||||
implements ValidatorConstraintInterface
|
||||
{
|
||||
validate(_value: unknown, args: ValidationArguments): boolean {
|
||||
const o = args.object as {
|
||||
objectionParts?: unknown[];
|
||||
newParts?: unknown[];
|
||||
};
|
||||
const partsLen = Array.isArray(o.objectionParts) ? o.objectionParts.length : 0;
|
||||
const newLen = Array.isArray(o.newParts) ? o.newParts.length : 0;
|
||||
return partsLen > 0 || newLen > 0;
|
||||
}
|
||||
|
||||
defaultMessage(): string {
|
||||
return "Provide at least one entry in objectionParts and/or newParts.";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user