UNPKG

facturacionelectronicapy-ts-xmlgen

Version:

Genera el contenido del archivo XML del Documento electrónico exigido por la SET

169 lines (168 loc) 5.56 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SectorAutomotorSchema = void 0; const zod_1 = require("zod"); const fuelTypes_table_1 = require("../../data/fuelTypes.table"); const vehicleOperationTypes_table_1 = require("../../data/vehicleOperationTypes.table"); const NumberLenght_1 = __importDefault(require("../../helpers/validation/NumberLenght")); const db_service_1 = __importDefault(require("../../services/db.service")); const ZodValidator_1 = __importDefault(require("../../helpers/validation/ZodValidator")); const Path_1 = require("../../helpers/Path"); const SDParser_1 = __importDefault(require("../../helpers/SDParser")); /**E8.5. Sector de automotores nuevos y usados (E770-E789) */ exports.SectorAutomotorSchema = zod_1.z .object({ // E771 tipo: zod_1.z .nativeEnum(vehicleOperationTypes_table_1.VehicleOperationType) .optional() .describe(SDParser_1.default.stringify('E771', { e: 'VehicleOperationType' })), // E773 chasis: zod_1.z .string() .length(17) .optional() .describe(SDParser_1.default.stringify('E773')), // E774 color: zod_1.z .string() .min(1) .max(10) .optional() .describe(SDParser_1.default.stringify('E774')), // E775 potencia: zod_1.z .number() .optional() .superRefine((value, ctx) => { if (value == undefined) return; new NumberLenght_1.default(value, ctx).int().max(4); }) .describe(SDParser_1.default.stringify('E775')), // E776 capacidadMotor: zod_1.z .number() .optional() .superRefine((value, ctx) => { if (value == undefined) return; new NumberLenght_1.default(value, ctx).int().max(4); }) .describe(SDParser_1.default.stringify('E776')), // E777 pesoNeto: zod_1.z .number() .optional() .superRefine((value, ctx) => { if (value == undefined) return; new NumberLenght_1.default(value, ctx).max(6).maxDecimals(4); }) .describe(SDParser_1.default.stringify('E777')), // E778 pesoBruto: zod_1.z .number() .optional() .superRefine((value, ctx) => { if (value == undefined) return; new NumberLenght_1.default(value, ctx).max(6).maxDecimals(4); }) .describe(SDParser_1.default.stringify('E778')), // E779 tipoCombustible: zod_1.z .nativeEnum(fuelTypes_table_1.FuelType) .optional() .describe(SDParser_1.default.stringify('E779', { e: 'FuelType' })), // E780 tipoCombustibleDescripcion: zod_1.z .string() .min(3) .max(20) .optional() .describe(SDParser_1.default.stringify('E780')), // E781 numeroMotor: zod_1.z .string() .min(1) .max(21) .optional() .describe(SDParser_1.default.stringify('E781')), // E782 // Capacidad máxima de tracción capacidadTraccion: zod_1.z .number() .optional() .superRefine((value, ctx) => { if (value == undefined) return; new NumberLenght_1.default(value, ctx).max(6).maxDecimals(4); }) .describe(SDParser_1.default.stringify('E782')), // E783o: zod_1.z .number() .optional() .superRefine((value, ctx) => { if (value == undefined) return; new NumberLenght_1.default(value, ctx).int().length(4); }) .describe(SDParser_1.default.stringify('E783')), // E784 tipoVehiculo: zod_1.z .string() .min(4) .max(10) .optional() .describe(SDParser_1.default.stringify('E784')), // E785 capacidadPasajeros: zod_1.z .number() .optional() .superRefine((value, ctx) => { if (value == undefined) return; new NumberLenght_1.default(value, ctx).int().max(3); }) .describe(SDParser_1.default.stringify('E785')), // E786 cilindradas: zod_1.z .string() .length(4) .optional() .describe(SDParser_1.default.stringify('E786')), }) .transform((data, ctx) => { const validator = new ZodValidator_1.default(ctx, data); /**E769 = 9 */ const isOtherFuelType = data.tipoCombustible == fuelTypes_table_1.FuelType.OTRO; // E780 - tipoCombustibleDescripcion { /* Si E769 = 9 describir el tipo de combustible */ if (data.tipoCombustible) { if (isOtherFuelType) { validator.requiredField('tipoCombustibleDescripcion'); } else if (data.tipoCombustible) { const foundFuelType = db_service_1.default.fuelTypes._findById(data.tipoCombustible); data.tipoCombustibleDescripcion = foundFuelType.description; } } } // ⚠️ esto no es del manual const pesoBrutoPath = new Path_1.Path('pesoBruto'); validator.validate('pesoNeto', Boolean(data.pesoNeto && data.pesoBruto && data.pesoNeto > data.pesoBruto), `$path no puede ser mayor que '${pesoBrutoPath}'`); return { ...data, // E772 tipoDescripcion: db_service_1.default.vehicleOperationTypes._findByIdIfExist(data.tipo)?.description, }; });