UNPKG

smppjs

Version:
33 lines 1.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.dtoValidation = void 0; const types_1 = require("../types"); const dtoValidation = ({ dto, MAX_LENGTH, DATE_TYPE, }) => { const dtoRecord = dto.command; if (MAX_LENGTH) { const validator = Object.entries(MAX_LENGTH); for (let index = 0; index < validator.length; index += 1) { const fieldName = validator[index][0]; if (dtoRecord[fieldName].value && dtoRecord[fieldName].value.toString().length + 1 > validator[index][1]) { throw new Error(`${validator[index][0]} need to be minor than ${validator[index][1]}`); } } } if (DATE_TYPE) { const dateValidator = Object.entries(DATE_TYPE); for (let index = 0; index < dateValidator.length; index += 1) { const fieldName = dateValidator[index][0]; const fieldType = dateValidator[index][1]; if (dtoRecord[fieldName].value) { const value = dtoRecord[fieldName].value.toString(); if (value) { if (value.endsWith('R', value.length - 1) && fieldType === types_1.DateType.ABSOLUTE) { throw new Error(`${dateValidator[index][0]} need to be relative ${dateValidator[index][1]}`); } } } } } }; exports.dtoValidation = dtoValidation; //# sourceMappingURL=dtoValidation.js.map