@digione/node-custom-api 0.1.9-beta14 → 0.1.9-beta16

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.
@@ -14,3 +14,6 @@ export declare const changeBodyParam: (value?: {}, { skipSystem, omit }?: {
14
14
  skipSystem?: boolean;
15
15
  omit?: any[];
16
16
  }) => (req: Request, res: Response, next: any) => any;
17
+ export declare const changeConfigParam: (value?: {}, { skipSystem }?: {
18
+ skipSystem?: boolean;
19
+ }) => (req: Request, res: Response, next: any) => any;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.changeBodyParam = exports.changeOptionParam = exports.changeQueryParam = exports.getQueryParamFile = exports.getQueryParamCUD = exports.getQueryParam = exports.getStremParam = exports.getAuthParam = void 0;
3
+ exports.changeConfigParam = exports.changeBodyParam = exports.changeOptionParam = exports.changeQueryParam = exports.getQueryParamFile = exports.getQueryParamCUD = exports.getQueryParam = exports.getStremParam = exports.getAuthParam = void 0;
4
4
  const helper_1 = require("../utils/helper");
5
5
  const _ = require("lodash");
6
6
  const getAuthParam = (req, res, next) => {
@@ -127,6 +127,7 @@ const getQueryParam = (req, res, next) => {
127
127
  };
128
128
  exports.getQueryParam = getQueryParam;
129
129
  const getQueryParamCUD = (req, res, next) => {
130
+ let config = res.locals.config || {};
130
131
  res.locals.option = res.locals.option || {};
131
132
  if (req.query.include) {
132
133
  try {
@@ -144,7 +145,7 @@ const getQueryParamCUD = (req, res, next) => {
144
145
  res.locals.option['records'] = String(req.query.records).split(',');
145
146
  }
146
147
  if (req.query.ids) {
147
- res.locals.option['ids'] = String(req.query.ids).split(',').slice(0, 25);
148
+ res.locals.option['ids'] = String(req.query.ids).split(',').slice(0, (config['query_ids'] || 25));
148
149
  }
149
150
  return (0, exports.getAuthParam)(req, res, () => {
150
151
  if (req.query.lang_code) {
@@ -218,3 +219,13 @@ const changeBodyParam = (value = {}, { skipSystem = false, omit = [] } = {}) =>
218
219
  return next();
219
220
  };
220
221
  exports.changeBodyParam = changeBodyParam;
222
+ const changeConfigParam = (value = {}, { skipSystem = false } = {}) => (req, res, next) => {
223
+ if (skipSystem && req.params.web_system_token) {
224
+ let bol = (typeof req.params.web != "undefined") || (req.params.web_system == req.params.web);
225
+ if (bol)
226
+ return next();
227
+ }
228
+ res.locals.config = Object.assign(Object.assign({}, res.locals.config || {}), value);
229
+ return next();
230
+ };
231
+ exports.changeConfigParam = changeConfigParam;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digione/node-custom-api",
3
- "version": "0.1.9-beta14",
3
+ "version": "0.1.9-beta16",
4
4
  "description": "Typescript node digione-api",
5
5
  "author": "Monchai Jirayupong <monchai.j@seven.co.th>",
6
6
  "license": "MIT",
package/utils/db.js CHANGED
@@ -37,7 +37,7 @@ const genWhere = (where = {}, { as = "", delimiter = ".", prefix = true, bracket
37
37
  let rawWhere = (Object.keys(where).concat(symbolKeys)).reduce((result, key) => {
38
38
  let value = where[key];
39
39
  if (typeof value !== 'undefined') {
40
- key = typeof (key) == "string" ? keyPrefix + "`" + key + "`" : key;
40
+ key = typeof (key) == "string" ? keyPrefix + "`" + (key.split('.').join("`.`")) + "`" : key;
41
41
  if (typeof (value) == "string") {
42
42
  value = SqlString.escape(value);
43
43
  }
package/utils/file.d.ts CHANGED
@@ -191,7 +191,8 @@ export declare class FileUtil {
191
191
  width?: number;
192
192
  height?: number;
193
193
  }): any;
194
- uploadRawFormat(files: Array<any>, { field }?: {
194
+ uploadRawFormat(files: Array<any>, { format, field }?: {
195
+ format?: boolean;
195
196
  field?: string[];
196
197
  }): Promise<any>;
197
198
  updateFile(id: string, input?: any, { paths }?: {
package/utils/file.js CHANGED
@@ -642,10 +642,10 @@ class FileUtil {
642
642
  }
643
643
  });
644
644
  }
645
- uploadRawFormat(files, { field = ['name', 'filename', 'path', 'mimetype', 'filesize', 'extension', 'type', 'height', 'width'] } = {}) {
645
+ uploadRawFormat(files, { format = false, field = ['name', 'filename', 'path', 'mimetype', 'filesize', 'extension', 'type', 'height', 'width'] } = {}) {
646
646
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
647
647
  let query = yield this.uploadRaw(files);
648
- return yield this.formatFile(0, 0, files, query, { format: true, field });
648
+ return yield this.formatFile(0, 0, files, query, { format, field });
649
649
  });
650
650
  }
651
651
  updateFile(id, input = {}, { paths = [] } = {}) {
package/utils/stream.js CHANGED
@@ -783,7 +783,7 @@ class StreamUtil {
783
783
  if (id_stream && (streams && streams.length)) {
784
784
  let file_id = [];
785
785
  yield Promise.all(streams.map(({ field_type, field_slug, field_data }) => tslib_1.__awaiter(this, void 0, void 0, function* () {
786
- if (field_type == "multiple" && field_data && field_data['choose_stream']) {
786
+ if (field_type == "multiple" && field_data && field_data['choose_stream'] && field_data['self_table'] != "yes") {
787
787
  let stream = yield stream_1.StreamModel.schema(this.ref, "_").findOne({ where: { id: field_data['choose_stream'] }, raw: true, attributes: ['stream_slug', 'stream_prefix'] });
788
788
  let table_f = stream['stream_prefix'] ? stream['stream_prefix'] + stream['stream_slug'] : stream['stream_slug'];
789
789
  yield (0, db_1.remove)(this.ref, `${table}_${table_f}`, { where: { row_id: id } });
@@ -240,8 +240,9 @@ const exportService = ({ file_type = undefined, export_type = [], limit = 200, s
240
240
  });
241
241
  exports.exportService = exportService;
242
242
  const printService = ({ print_type = [], schema = {} } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
243
+ let config = res.locals.config || {};
243
244
  if (req.query.ids) {
244
- res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), { ids: String(req.query.ids).split(',') });
245
+ res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), { ids: String(req.query.ids).split(',').slice(0, (config['query_ids'] || 25)) });
245
246
  }
246
247
  if (print_type && !req.query.print_type) {
247
248
  req.query.print_type = print_type[0];
@@ -261,8 +262,9 @@ const printService = ({ print_type = [], schema = {} } = {}) => (req, res, next)
261
262
  });
262
263
  exports.printService = printService;
263
264
  const dataService = ({ schema = {} } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
265
+ let config = res.locals.config || {};
264
266
  if (req.query.ids) {
265
- res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), { ids: String(req.query.ids).split(',') });
267
+ res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), { ids: String(req.query.ids).split(',').slice(0, (config['query_ids'] || 25)) });
266
268
  }
267
269
  let option = Object.keys(schema || {});
268
270
  if (option.length) {