mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
23 lines
743 B
TypeScript
23 lines
743 B
TypeScript
import { registerDecorator, ValidationOptions, ValidationArguments } from 'class-validator'
|
|
import { Decimal } from 'decimal.js-light'
|
|
|
|
export function IsPositiveDecimal(validationOptions?: ValidationOptions) {
|
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
return function (object: Object, propertyName: string) {
|
|
registerDecorator({
|
|
name: 'isPositiveDecimal',
|
|
target: object.constructor,
|
|
propertyName,
|
|
options: validationOptions,
|
|
validator: {
|
|
validate(value: Decimal) {
|
|
return value.greaterThan(0)
|
|
},
|
|
defaultMessage(args: ValidationArguments) {
|
|
return `The ${propertyName} must be a positive value ${args.property}`
|
|
},
|
|
},
|
|
})
|
|
}
|
|
}
|