|
@ -15,10 +15,33 @@ import { |
|
|
IsNumber, |
|
|
IsNumber, |
|
|
IsOptional, |
|
|
IsOptional, |
|
|
IsString, |
|
|
IsString, |
|
|
Min |
|
|
Min, |
|
|
|
|
|
ValidationArguments, |
|
|
|
|
|
ValidationOptions, |
|
|
|
|
|
registerDecorator |
|
|
} from 'class-validator'; |
|
|
} from 'class-validator'; |
|
|
import { isString } from 'lodash'; |
|
|
import { isString } from 'lodash'; |
|
|
|
|
|
|
|
|
|
|
|
function IsQuantityValid(validationOptions?: ValidationOptions) { |
|
|
|
|
|
return function (object: Object, propertyName: string) { |
|
|
|
|
|
registerDecorator({ |
|
|
|
|
|
name: 'isQuantityValid', |
|
|
|
|
|
target: object.constructor, |
|
|
|
|
|
propertyName: propertyName, |
|
|
|
|
|
options: validationOptions, |
|
|
|
|
|
validator: { |
|
|
|
|
|
validate(value: any, args: ValidationArguments) { |
|
|
|
|
|
const order = args.object as CreateOrderDto; |
|
|
|
|
|
return order.type !== 'SPLIT' ? value >= 0 : true; |
|
|
|
|
|
}, |
|
|
|
|
|
defaultMessage(args: ValidationArguments) { |
|
|
|
|
|
return `Quantity must not be less than 0 unless the type is ${Type.SPLIT}`; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
export class CreateOrderDto { |
|
|
export class CreateOrderDto { |
|
|
@IsOptional() |
|
|
@IsOptional() |
|
|
@IsString() |
|
|
@IsString() |
|
@ -54,7 +77,7 @@ export class CreateOrderDto { |
|
|
fee: number; |
|
|
fee: number; |
|
|
|
|
|
|
|
|
@IsNumber() |
|
|
@IsNumber() |
|
|
@Min(0) |
|
|
@IsQuantityValid() |
|
|
quantity: number; |
|
|
quantity: number; |
|
|
|
|
|
|
|
|
@IsString() |
|
|
@IsString() |
|
|