Validation for prices and objection

This commit is contained in:
SepehrYahyaee
2026-05-20 11:08:47 +03:30
parent 511d478064
commit e4dfe7c572
18 changed files with 467 additions and 60 deletions

View 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.";
}
}