@digione/node-custom-api 0.1.5 → 0.1.6-beta1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digione/node-custom-api",
3
- "version": "0.1.5",
3
+ "version": "0.1.6-beta1",
4
4
  "description": "Typescript node digione-api",
5
5
  "author": "Monchai Jirayupong <monchai.j@seven.co.th>",
6
6
  "license": "MIT",
@@ -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;
@@ -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
  }
@@ -228,6 +231,11 @@ const exportService = ({ file_type = undefined, export_type = [], limit = 200, s
228
231
  if (req.query.export_type) {
229
232
  res.locals.option['export_type'] = req.query.export_type;
230
233
  }
234
+ let option = Object.keys(schema || {});
235
+ if (option.length) {
236
+ let value = _.pick(req.query, option);
237
+ res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), value);
238
+ }
231
239
  return (0, exports.paramService)(Joi.object().keys(Object.assign({ all_data: Joi.number().allow(null, ''), export_type: Joi.string().valid(...export_type), limit: Joi.number().max(limit) }, schema)).unknown())(req, res, next);
232
240
  });
233
241
  exports.exportService = exportService;
@@ -244,6 +252,11 @@ const printService = ({ print_type = [], schema = {} } = {}) => (req, res, next)
244
252
  if (req.query.preset) {
245
253
  res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), { preset: req.query.preset });
246
254
  }
255
+ let option = Object.keys(schema || {});
256
+ if (option.length) {
257
+ let value = _.pick(req.query, option);
258
+ res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), value);
259
+ }
247
260
  return (0, exports.paramService)(Joi.object().keys(Object.assign({ ids: Joi.string().required(), print_type: Joi.string().valid(...print_type), preset: Joi.string() }, schema)).unknown())(req, res, next);
248
261
  });
249
262
  exports.printService = printService;
@@ -251,6 +264,11 @@ const dataService = ({ schema = {} } = {}) => (req, res, next) => tslib_1.__awai
251
264
  if (req.query.ids) {
252
265
  res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), { ids: String(req.query.ids).split(',') });
253
266
  }
267
+ let option = Object.keys(schema || {});
268
+ if (option.length) {
269
+ let value = _.pick(req.query, option);
270
+ res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), value);
271
+ }
254
272
  return (0, exports.paramService)(Joi.object().keys(Object.assign({ ids: Joi.string().required(), preset: Joi.string() }, schema)).unknown())(req, res, next);
255
273
  });
256
274
  exports.dataService = dataService;
@@ -261,6 +279,11 @@ const fieldService = ({ field = [], schema = {} } = {}) => (req, res, next) => t
261
279
  if (req.query.field) {
262
280
  res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), { field: req.query.field });
263
281
  }
282
+ let option = Object.keys(schema || {});
283
+ if (option.length) {
284
+ let value = _.pick(req.query, option);
285
+ res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), value);
286
+ }
264
287
  return (0, exports.paramService)(Joi.object().keys(Object.assign({ field: Joi.string().valid(...field) }, schema)).unknown())(req, res, next);
265
288
  });
266
289
  exports.fieldService = fieldService;