@digione/node-custom-api 0.2.0-alpha4 → 0.2.0-alpha6

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.
@@ -1,9 +1,9 @@
1
1
  import { Request, Response } from 'express';
2
2
  export declare const getAuthParam: (req: Request, res: Response, next: any) => void;
3
3
  export declare const getStremParam: (req: Request, res: Response, next: any) => void;
4
- export declare const getQueryParam: (req: Request, res: Response, next: any) => void;
4
+ export declare const getQueryParam: (req: Request, res: Response, next: any) => Promise<void | Response<any, Record<string, any>>>;
5
5
  export declare const getQueryParamCUD: (req: Request, res: Response, next: any) => void;
6
- export declare const getQueryParamFile: (req: Request, res: Response, next: any) => void;
6
+ export declare const getQueryParamFile: (req: Request, res: Response, next: any) => Promise<void | Response<any, Record<string, any>>>;
7
7
  export declare const changeQueryParam: (value?: {}, { skipSystem }?: {
8
8
  skipSystem?: boolean;
9
9
  }) => (req: Request, res: Response, next: any) => any;
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.changeConfigParam = exports.changeBodyParam = exports.changeOptionParam = exports.changeQueryParam = exports.getQueryParamFile = exports.getQueryParamCUD = exports.getQueryParam = exports.getStremParam = exports.getAuthParam = void 0;
4
+ const tslib_1 = require("tslib");
4
5
  const helper_1 = require("../utils/helper");
6
+ const errors_1 = require("../errors");
5
7
  const _ = require("lodash");
6
8
  const getAuthParam = (req, res, next) => {
7
9
  res.locals.option['hostname'] = ((0, helper_1.getENV)('NODE_ENV') == 'development' ? 'http' : 'https') + '://' + req.get('host');
@@ -77,7 +79,8 @@ const getStremParam = (req, res, next) => {
77
79
  });
78
80
  };
79
81
  exports.getStremParam = getStremParam;
80
- const getQueryParam = (req, res, next) => {
82
+ const getQueryParam = (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
83
+ let config = res.locals.config || {};
81
84
  res.locals.option = res.locals.option || {};
82
85
  res.locals.option['lang_code'] = 'en';
83
86
  res.locals.option['currency'] = 'thb';
@@ -93,8 +96,20 @@ const getQueryParam = (req, res, next) => {
93
96
  else {
94
97
  res.locals.include = {};
95
98
  }
99
+ if (config['maxQueryLimit']) {
100
+ req.query.limit = req.query.limit || config['maxQueryLimit'];
101
+ }
96
102
  if (req.query.limit) {
97
103
  res.locals.option['limit'] = Number(req.query.limit);
104
+ if (config['maxQueryLimit'] && res.locals.option['limit'] > config['maxQueryLimit']) {
105
+ try {
106
+ yield (0, errors_1.paramError)(`"limit" must be less than or equal to ${config['maxQueryLimit']}`, { field: "limit" });
107
+ }
108
+ catch (err) {
109
+ let error = new errors_1.CustomError(err);
110
+ return res.status(error.code).send(error);
111
+ }
112
+ }
98
113
  }
99
114
  if (req.query.offset) {
100
115
  res.locals.option['offset'] = Number(req.query.offset);
@@ -124,7 +139,7 @@ const getQueryParam = (req, res, next) => {
124
139
  }
125
140
  return next();
126
141
  });
127
- };
142
+ });
128
143
  exports.getQueryParam = getQueryParam;
129
144
  const getQueryParamCUD = (req, res, next) => {
130
145
  let config = res.locals.config || {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digione/node-custom-api",
3
- "version": "0.2.0-alpha4",
3
+ "version": "0.2.0-alpha6",
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
@@ -486,8 +486,8 @@ class StreamUtil {
486
486
  }
487
487
  return Object.assign({ field_slug: i['lang_code'], field_name: `${convert_option ? (0, i18n_1.__)({ phrase: item['field_name'], locale: lang_code }) : item['field_name']} (${i['lang_code']})`, field_type: item['field_type'], field_name_raw: item['field_name'] ? item['field_name'] : "", is_required: item['is_required'] }, include);
488
488
  });
489
- fields.push(Object.assign(Object.assign({}, item), { field_data }));
490
489
  if (item['field_type'] != "stream") {
490
+ fields.push(Object.assign(Object.assign({}, item), { field_data }));
491
491
  continue;
492
492
  }
493
493
  }
@@ -685,7 +685,7 @@ class StreamUtil {
685
685
  if (field_data['choose_stream']) {
686
686
  let stream = yield stream_1.StreamModel.schema(this.ref, "_").findOne({ where: { id: field_data['choose_stream'] }, raw: true, attributes: ['stream_slug', 'stream_namespace'] });
687
687
  if (stream) {
688
- item['stream'] = yield this.findField(stream['stream_slug'], stream['stream_namespace'], { field_only: true, convert_option: true });
688
+ item['stream'] = yield this.findField(stream['stream_slug'], stream['stream_namespace'], { option, lang_code, field_only: true, convert_option: true });
689
689
  }
690
690
  }
691
691
  }
@@ -104,8 +104,9 @@ const fileService = (setup, { userfiles = false, required = false, fileSize = 0,
104
104
  }
105
105
  let option = setup(validate);
106
106
  let upload = userfiles ? option.array("userfiles", maxCount) : option.any();
107
+ let schema = userfiles ? { tags: Joi.array().allow('', null).items(Joi.object().keys({ slug: Joi.string(), type: Joi.string() })) } : { tags: Joi.any() };
107
108
  return upload(req, res, (err) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
108
- return (0, exports.validateService)(Joi.object().keys({ tags: Joi.array().allow('', null).items(Joi.object().keys({ slug: Joi.string(), type: Joi.string() })) }).unknown(), { field_omit: [] })(req, res, () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
109
+ return (0, exports.validateService)(Joi.object().keys(schema).unknown(), { field_omit: [] })(req, res, () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
109
110
  try {
110
111
  let field = userfiles ? "userfiles" : undefined;
111
112
  if (err) {