forked from Yara724/api
Validation for prices and objection
This commit is contained in:
29
src/common/validators/objection-part-content.validator.ts
Normal file
29
src/common/validators/objection-part-content.validator.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import {
|
||||
ValidationArguments,
|
||||
ValidatorConstraint,
|
||||
ValidatorConstraintInterface,
|
||||
} from "class-validator";
|
||||
|
||||
@ValidatorConstraint({ name: "objectionPartHasContent", async: false })
|
||||
export class ObjectionPartHasContentConstraint
|
||||
implements ValidatorConstraintInterface
|
||||
{
|
||||
validate(_value: unknown, args: ValidationArguments): boolean {
|
||||
const o = args.object as {
|
||||
reason?: string;
|
||||
partPrice?: string;
|
||||
partSalary?: string;
|
||||
};
|
||||
const hasReason =
|
||||
typeof o.reason === "string" && o.reason.trim().length >= 3;
|
||||
const hasPrice =
|
||||
o.partPrice != null && String(o.partPrice).trim() !== "";
|
||||
const hasSalary =
|
||||
o.partSalary != null && String(o.partSalary).trim() !== "";
|
||||
return hasReason || hasPrice || hasSalary;
|
||||
}
|
||||
|
||||
defaultMessage(): string {
|
||||
return "Each objection line needs a reason (min 3 characters) and/or proposed partPrice / partSalary.";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user