2024-07-09 16:21:12 +00:00
|
|
|
import Joi from "joi";
|
|
|
|
|
import { Result, RuleValidator } from "../../domain";
|
|
|
|
|
|
2024-07-17 18:10:07 +00:00
|
|
|
export interface IQuantity_DTO {
|
|
|
|
|
amount: number | null;
|
2024-07-15 15:41:42 +00:00
|
|
|
scale: number;
|
2024-07-09 16:21:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function ensureQuantity_DTOIsValid(quantity: IQuantity_Request_DTO) {
|
|
|
|
|
const schema = Joi.object({
|
|
|
|
|
amount: Joi.number(),
|
2024-07-15 15:41:42 +00:00
|
|
|
scale: Joi.number(),
|
2024-07-09 16:21:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const result = RuleValidator.validate<IQuantity_Request_DTO>(schema, quantity);
|
|
|
|
|
|
|
|
|
|
if (result.isFailure) {
|
|
|
|
|
return Result.fail(result.error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Result.ok(true);
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-17 18:10:07 +00:00
|
|
|
export interface IQuantity_Request_DTO extends IQuantity_DTO {}
|
|
|
|
|
export interface IQuantity_Response_DTO extends IQuantity_DTO {}
|