27 lines
608 B
TypeScript
27 lines
608 B
TypeScript
import Joi from "joi";
|
|
import { Result, RuleValidator } from "../../domain";
|
|
|
|
export interface IMoney_Request_DTO {
|
|
amount: number;
|
|
precision: number;
|
|
currency: string;
|
|
}
|
|
|
|
export function ensureMoney_DTOIsValid(money: IMoney_Request_DTO) {
|
|
const schema = Joi.object({
|
|
amount: Joi.number(),
|
|
precision: Joi.number(),
|
|
currency: Joi.string(),
|
|
});
|
|
|
|
const result = RuleValidator.validate<IMoney_Request_DTO>(schema, money);
|
|
|
|
if (result.isFailure) {
|
|
return Result.fail(result.error);
|
|
}
|
|
|
|
return Result.ok(true);
|
|
}
|
|
|
|
export interface IMoney_Response_DTO extends IMoney_Request_DTO {}
|