@digione/node-custom-api 0.1.6 → 0.1.7-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.6",
3
+ "version": "0.1.7-beta1",
4
4
  "description": "Typescript node digione-api",
5
5
  "author": "Monchai Jirayupong <monchai.j@seven.co.th>",
6
6
  "license": "MIT",
package/utils/stream.js CHANGED
@@ -743,7 +743,7 @@ class StreamUtil {
743
743
  if (!Object.keys(data).length) {
744
744
  return Promise.reject(errors_1.generalError.BAD_REQUEST);
745
745
  }
746
- if (req.files) {
746
+ if (req && req.files) {
747
747
  files = _.reduce(req.files, (total, item) => {
748
748
  total[item['fieldname']] = item;
749
749
  return total;
@@ -1742,7 +1742,7 @@ class StreamUtil {
1742
1742
  getValidator(streams, { schema = {}, input = {}, req = {}, isNew = false, lang = [], required = true, stripUnknown = false } = {}) {
1743
1743
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
1744
1744
  let field_lang = [];
1745
- let file = (req.file ? [req.file] : [].concat(req.files || [])).reduce((total, item) => Object.assign(total, { [item['fieldname']]: item }), {});
1745
+ let file = req ? ((req.file ? [req.file] : [].concat(req.files || [])).reduce((total, item) => Object.assign(total, { [item['fieldname']]: item }), {})) : {};
1746
1746
  streams.forEach(({ field_type, field_slug, is_required, is_lang, field_data, data }) => {
1747
1747
  let field;
1748
1748
  field_data = field_data || {};
@@ -53,5 +53,9 @@ export declare const fieldService: ({ field, schema }?: {
53
53
  field?: any[];
54
54
  schema?: {};
55
55
  }) => (req: any, res: any, next: any) => Promise<any>;
56
+ export declare const convertService: ({ convert_type, schema }?: {
57
+ convert_type?: any[];
58
+ schema?: {};
59
+ }) => (req: any, res: any, next: any) => Promise<any>;
56
60
  export declare const createdByValidate: (req: any, res: any, next: any) => Promise<any>;
57
61
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createdByValidate = exports.fieldService = exports.dataService = exports.printService = exports.exportService = exports.importService = exports.streamService = exports.multiService = exports.fileService = exports.paramService = exports.validateService = exports.validate = void 0;
3
+ exports.createdByValidate = exports.convertService = exports.fieldService = exports.dataService = exports.printService = exports.exportService = exports.importService = exports.streamService = exports.multiService = exports.fileService = exports.paramService = exports.validateService = exports.validate = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const Joi = require("joi");
6
6
  const errors_1 = require("../errors");
@@ -231,6 +231,11 @@ const exportService = ({ file_type = undefined, export_type = [], limit = 200, s
231
231
  if (req.query.export_type) {
232
232
  res.locals.option['export_type'] = req.query.export_type;
233
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
+ }
234
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);
235
240
  });
236
241
  exports.exportService = exportService;
@@ -247,6 +252,11 @@ const printService = ({ print_type = [], schema = {} } = {}) => (req, res, next)
247
252
  if (req.query.preset) {
248
253
  res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), { preset: req.query.preset });
249
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
+ }
250
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);
251
261
  });
252
262
  exports.printService = printService;
@@ -254,6 +264,11 @@ const dataService = ({ schema = {} } = {}) => (req, res, next) => tslib_1.__awai
254
264
  if (req.query.ids) {
255
265
  res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), { ids: String(req.query.ids).split(',') });
256
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
+ }
257
272
  return (0, exports.paramService)(Joi.object().keys(Object.assign({ ids: Joi.string().required(), preset: Joi.string() }, schema)).unknown())(req, res, next);
258
273
  });
259
274
  exports.dataService = dataService;
@@ -264,9 +279,18 @@ const fieldService = ({ field = [], schema = {} } = {}) => (req, res, next) => t
264
279
  if (req.query.field) {
265
280
  res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), { field: req.query.field });
266
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
+ }
267
287
  return (0, exports.paramService)(Joi.object().keys(Object.assign({ field: Joi.string().valid(...field) }, schema)).unknown())(req, res, next);
268
288
  });
269
289
  exports.fieldService = fieldService;
290
+ const convertService = ({ convert_type = [], schema = {} } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
291
+ return (0, exports.validateService)(Joi.object().keys(Object.assign({ ids: Joi.array().items(Joi.number()).min(1), convert_type: Joi.string().valid(...convert_type) }, schema)).unknown())(req, res, next);
292
+ });
293
+ exports.convertService = convertService;
270
294
  exports.createdByValidate = (0, exports.validateService)(Joi.object().keys({
271
295
  created_by: Joi.alternatives().try(Joi.string(), Joi.number()).required()
272
296
  }).unknown());