sigo-entities 0.0.111 → 0.0.113
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 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.js +13 -4
- package/dist/index.mjs +13 -4
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -4,9 +4,7 @@ declare class DestinatarioDTO {
|
|
|
4
4
|
Email: string;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
declare function validateAndFormatData<T extends object>(data: any, dtoClass: new () => T,
|
|
8
|
-
[k: string]: any;
|
|
9
|
-
}>;
|
|
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>>;
|
|
10
8
|
|
|
11
9
|
declare class AlmacenDTO {
|
|
12
10
|
Codigo: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,9 +4,7 @@ declare class DestinatarioDTO {
|
|
|
4
4
|
Email: string;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
declare function validateAndFormatData<T extends object>(data: any, dtoClass: new () => T,
|
|
8
|
-
[k: string]: any;
|
|
9
|
-
}>;
|
|
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>>;
|
|
10
8
|
|
|
11
9
|
declare class AlmacenDTO {
|
|
12
10
|
Codigo: string;
|
package/dist/index.js
CHANGED
|
@@ -240,18 +240,27 @@ 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
|
+
throw new Error(`Debes especificar al menos una propiedad a validar`);
|
|
246
|
+
}
|
|
244
247
|
const instance = (0, import_class_transformer2.plainToInstance)(dtoClass, data, { excludeExtraneousValues: true });
|
|
245
|
-
const errors = await (0, import_class_validator2.validate)(instance, { skipMissingProperties });
|
|
248
|
+
const errors = await (0, import_class_validator2.validate)(instance, { skipMissingProperties: !!propertiesToValidate });
|
|
246
249
|
if (errors.length > 0) {
|
|
247
250
|
const formattedErrors = formatErrors(errors);
|
|
248
251
|
const errorMessage = `Response validation failed: ${formattedErrors[0]}`;
|
|
249
252
|
throw new Error(errorMessage);
|
|
250
253
|
}
|
|
251
|
-
if (
|
|
252
|
-
|
|
254
|
+
if (propertiesToValidate) {
|
|
255
|
+
const result = Object.fromEntries(
|
|
253
256
|
Object.entries(instance).filter(([key, value]) => value !== void 0)
|
|
254
257
|
);
|
|
258
|
+
for (const item of propertiesToValidate) {
|
|
259
|
+
if (!(item in result)) {
|
|
260
|
+
throw new Error(`No se envi\xF3 la propiedad ${[item]} en la data (primer par\xE1metro)`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return result;
|
|
255
264
|
}
|
|
256
265
|
return instance;
|
|
257
266
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -43,18 +43,27 @@ 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
|
+
throw new Error(`Debes especificar al menos una propiedad a validar`);
|
|
49
|
+
}
|
|
47
50
|
const instance = plainToInstance(dtoClass, data, { excludeExtraneousValues: true });
|
|
48
|
-
const errors = await validate(instance, { skipMissingProperties });
|
|
51
|
+
const errors = await validate(instance, { skipMissingProperties: !!propertiesToValidate });
|
|
49
52
|
if (errors.length > 0) {
|
|
50
53
|
const formattedErrors = formatErrors(errors);
|
|
51
54
|
const errorMessage = `Response validation failed: ${formattedErrors[0]}`;
|
|
52
55
|
throw new Error(errorMessage);
|
|
53
56
|
}
|
|
54
|
-
if (
|
|
55
|
-
|
|
57
|
+
if (propertiesToValidate) {
|
|
58
|
+
const result = Object.fromEntries(
|
|
56
59
|
Object.entries(instance).filter(([key, value]) => value !== void 0)
|
|
57
60
|
);
|
|
61
|
+
for (const item of propertiesToValidate) {
|
|
62
|
+
if (!(item in result)) {
|
|
63
|
+
throw new Error(`No se envi\xF3 la propiedad ${[item]} en la data (primer par\xE1metro)`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
58
67
|
}
|
|
59
68
|
return instance;
|
|
60
69
|
}
|