@digione/node-custom-api 0.1.5 → 0.1.6
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/package.json +1 -1
- package/utils/validator.d.ts +2 -1
- package/utils/validator.js +4 -1
package/package.json
CHANGED
package/utils/validator.d.ts
CHANGED
|
@@ -12,11 +12,12 @@ export declare const validate: (schema: Joi.AnySchema, body?: any, { arrayIndex,
|
|
|
12
12
|
arrayIndex?: boolean;
|
|
13
13
|
prefixMessage?: string;
|
|
14
14
|
}) => Promise<any>;
|
|
15
|
-
export declare const validateService: (schema: Joi.ObjectSchema, { organ_id, created_by, web_id, purgeUpdate }?: {
|
|
15
|
+
export declare const validateService: (schema: Joi.ObjectSchema, { organ_id, created_by, web_id, purgeUpdate, field_omit }?: {
|
|
16
16
|
organ_id?: boolean;
|
|
17
17
|
created_by?: boolean;
|
|
18
18
|
web_id?: boolean;
|
|
19
19
|
purgeUpdate?: boolean;
|
|
20
|
+
field_omit?: string[];
|
|
20
21
|
}) => (req: any, res: any, next: any) => Promise<any>;
|
|
21
22
|
export declare const paramService: (schema: Joi.AnySchema) => (req: any, res: any, next: any) => Promise<any>;
|
|
22
23
|
export declare const fileService: (setup: any, { userfiles, required, fileSize, fileTypes, maxCount, qualityImage, resizeImage }?: OptionFile) => (req: any, res: any, next: any) => any;
|
package/utils/validator.js
CHANGED
|
@@ -40,7 +40,7 @@ const validate = (schema, body = {}, { arrayIndex = false, prefixMessage = "" }
|
|
|
40
40
|
return result.value;
|
|
41
41
|
});
|
|
42
42
|
exports.validate = validate;
|
|
43
|
-
const validateService = (schema, { organ_id = true, created_by = true, web_id = true, purgeUpdate = true } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
const validateService = (schema, { organ_id = true, created_by = true, web_id = true, purgeUpdate = true, field_omit = ["id"] } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
44
44
|
if (created_by) {
|
|
45
45
|
const token = req.headers['authorization'] ? req.headers['authorization'].split(' ')[1] : null;
|
|
46
46
|
if (token && !res.locals.user_id) {
|
|
@@ -70,6 +70,9 @@ const validateService = (schema, { organ_id = true, created_by = true, web_id =
|
|
|
70
70
|
if (web_id && res.locals.web_id) {
|
|
71
71
|
req.body['web_id'] = res.locals.web_id;
|
|
72
72
|
}
|
|
73
|
+
if (field_omit && field_omit.length) {
|
|
74
|
+
req.body = _.omit(req.body, field_omit);
|
|
75
|
+
}
|
|
73
76
|
try {
|
|
74
77
|
req.body = yield (0, exports.validate)(schema, req.body);
|
|
75
78
|
}
|