sigo-entities 0.0.112 → 0.0.114
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +16 -3
- package/dist/index.mjs +16 -3
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -4,7 +4,7 @@ declare class DestinatarioDTO {
|
|
|
4
4
|
Email: string;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
declare function validateAndFormatData<T extends object, Skip extends
|
|
7
|
+
declare function validateAndFormatData<T extends object, Skip extends undefined | (keyof T)[] = undefined>(data: any, dtoClass: new () => T, propertiesToValidate?: Skip): Promise<Skip extends undefined ? T : Partial<T>>;
|
|
8
8
|
|
|
9
9
|
declare class AlmacenDTO {
|
|
10
10
|
Codigo: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ declare class DestinatarioDTO {
|
|
|
4
4
|
Email: string;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
declare function validateAndFormatData<T extends object, Skip extends
|
|
7
|
+
declare function validateAndFormatData<T extends object, Skip extends undefined | (keyof T)[] = undefined>(data: any, dtoClass: new () => T, propertiesToValidate?: Skip): Promise<Skip extends undefined ? T : Partial<T>>;
|
|
8
8
|
|
|
9
9
|
declare class AlmacenDTO {
|
|
10
10
|
Codigo: string;
|
package/dist/index.js
CHANGED
|
@@ -240,18 +240,31 @@ var import_class_validator55 = require("class-validator");
|
|
|
240
240
|
// src/shared/utils/validarYFormatearDatos.ts
|
|
241
241
|
var import_class_transformer2 = require("class-transformer");
|
|
242
242
|
var import_class_validator2 = require("class-validator");
|
|
243
|
-
async function validateAndFormatData(data, dtoClass,
|
|
243
|
+
async function validateAndFormatData(data, dtoClass, propertiesToValidate) {
|
|
244
|
+
if (propertiesToValidate && propertiesToValidate.length === 0) {
|
|
245
|
+
if (propertiesToValidate.length === 0) {
|
|
246
|
+
throw new Error(`Debes especificar al menos una propiedad a validar`);
|
|
247
|
+
}
|
|
248
|
+
data = Object.fromEntries(
|
|
249
|
+
Object.entries(data).filter(([key]) => propertiesToValidate.includes(key))
|
|
250
|
+
);
|
|
251
|
+
}
|
|
244
252
|
const instance = (0, import_class_transformer2.plainToInstance)(dtoClass, data, { excludeExtraneousValues: true });
|
|
245
|
-
const errors = await (0, import_class_validator2.validate)(instance, { skipMissingProperties });
|
|
253
|
+
const errors = await (0, import_class_validator2.validate)(instance, { skipMissingProperties: !!propertiesToValidate });
|
|
246
254
|
if (errors.length > 0) {
|
|
247
255
|
const formattedErrors = formatErrors(errors);
|
|
248
256
|
const errorMessage = `Response validation failed: ${formattedErrors[0]}`;
|
|
249
257
|
throw new Error(errorMessage);
|
|
250
258
|
}
|
|
251
|
-
if (
|
|
259
|
+
if (propertiesToValidate) {
|
|
252
260
|
const result = Object.fromEntries(
|
|
253
261
|
Object.entries(instance).filter(([key, value]) => value !== void 0)
|
|
254
262
|
);
|
|
263
|
+
for (const item of propertiesToValidate) {
|
|
264
|
+
if (!(item in result)) {
|
|
265
|
+
throw new Error(`No se envi\xF3 la propiedad ${[item]} en la data (primer par\xE1metro)`);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
255
268
|
return result;
|
|
256
269
|
}
|
|
257
270
|
return instance;
|
package/dist/index.mjs
CHANGED
|
@@ -43,18 +43,31 @@ import { IsArray as IsArray6, IsEmail as IsEmail2, IsNotEmpty as IsNotEmpty53, I
|
|
|
43
43
|
// src/shared/utils/validarYFormatearDatos.ts
|
|
44
44
|
import { plainToInstance } from "class-transformer";
|
|
45
45
|
import { validate } from "class-validator";
|
|
46
|
-
async function validateAndFormatData(data, dtoClass,
|
|
46
|
+
async function validateAndFormatData(data, dtoClass, propertiesToValidate) {
|
|
47
|
+
if (propertiesToValidate && propertiesToValidate.length === 0) {
|
|
48
|
+
if (propertiesToValidate.length === 0) {
|
|
49
|
+
throw new Error(`Debes especificar al menos una propiedad a validar`);
|
|
50
|
+
}
|
|
51
|
+
data = Object.fromEntries(
|
|
52
|
+
Object.entries(data).filter(([key]) => propertiesToValidate.includes(key))
|
|
53
|
+
);
|
|
54
|
+
}
|
|
47
55
|
const instance = plainToInstance(dtoClass, data, { excludeExtraneousValues: true });
|
|
48
|
-
const errors = await validate(instance, { skipMissingProperties });
|
|
56
|
+
const errors = await validate(instance, { skipMissingProperties: !!propertiesToValidate });
|
|
49
57
|
if (errors.length > 0) {
|
|
50
58
|
const formattedErrors = formatErrors(errors);
|
|
51
59
|
const errorMessage = `Response validation failed: ${formattedErrors[0]}`;
|
|
52
60
|
throw new Error(errorMessage);
|
|
53
61
|
}
|
|
54
|
-
if (
|
|
62
|
+
if (propertiesToValidate) {
|
|
55
63
|
const result = Object.fromEntries(
|
|
56
64
|
Object.entries(instance).filter(([key, value]) => value !== void 0)
|
|
57
65
|
);
|
|
66
|
+
for (const item of propertiesToValidate) {
|
|
67
|
+
if (!(item in result)) {
|
|
68
|
+
throw new Error(`No se envi\xF3 la propiedad ${[item]} en la data (primer par\xE1metro)`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
58
71
|
return result;
|
|
59
72
|
}
|
|
60
73
|
return instance;
|