@digione/node-custom-api 0.1.9-beta9 → 0.2.0-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.
@@ -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['maxQueryIds'] || 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-beta9",
3
+ "version": "0.2.0-beta1",
4
4
  "description": "Typescript node digione-api",
5
5
  "author": "Monchai Jirayupong <monchai.j@seven.co.th>",
6
6
  "license": "MIT",
package/utils/auth.d.ts CHANGED
@@ -3,8 +3,10 @@ export declare const getTokenFromReq: (req: any) => any;
3
3
  export declare class AuthUtil {
4
4
  ref: string;
5
5
  constructor(ref: string);
6
- create(id: any, { include }?: {
6
+ create(id: any, { include, include_token, setting }?: {
7
7
  include?: {};
8
+ include_token?: {};
9
+ setting?: {};
8
10
  }): Promise<{
9
11
  refresh_token: string;
10
12
  access_token: string;
package/utils/auth.js CHANGED
@@ -11,7 +11,7 @@ const authError_1 = require("../errors/authError");
11
11
  const jwt = require("jsonwebtoken");
12
12
  const signToken = (id, expIn, opt = {}) => {
13
13
  const date = (0, helper_1.getDateTime)();
14
- return jwt.sign(Object.assign({ id: id, createAt: date, expAt: date.add(expIn, 'days') }, opt), (0, helper_1.getENV)('JWT_SECRET'));
14
+ return jwt.sign(Object.assign({ id: id, createAt: date, expAt: date.clone().add(expIn, 'days') }, opt), (0, helper_1.getENV)('JWT_SECRET'));
15
15
  };
16
16
  const getIdFromReq = (req) => {
17
17
  try {
@@ -30,14 +30,19 @@ class AuthUtil {
30
30
  constructor(ref) {
31
31
  this.ref = ref;
32
32
  }
33
- create(id, { include = {} } = {}) {
33
+ create(id, { include = {}, include_token = {}, setting = {} } = {}) {
34
34
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
35
35
  let refreshTokenUUID = (0, helper_1.getUUID)();
36
36
  let include_access = {};
37
37
  if (Object.keys(include).length) {
38
38
  include_access['setting'] = JSON.stringify(include);
39
39
  }
40
- let input = Object.assign({ id: refreshTokenUUID, user_id: id, expired_at: (0, helper_1.getDateTime)().add((0, helper_1.getENV)('REFRESH_TOKEN_AGE'), 'days'), token: signToken(id, (0, helper_1.getENV)('REFRESH_TOKEN_AGE'), { refresh_token_id: refreshTokenUUID }), accessToken: Object.assign({ user_id: id, expired_at: (0, helper_1.getDateTime)().add((0, helper_1.getENV)('ACCESS_TOKEN_AGE'), 'days'), token: signToken(id, (0, helper_1.getENV)('ACCESS_TOKEN_AGE'), { refresh_token_id: refreshTokenUUID }) }, include_access) }, include);
40
+ let rf_expire_in = Number(setting['expire_in'] || (0, helper_1.getENV)('REFRESH_TOKEN_AGE', 1));
41
+ let ac_expire_in = Number((0, helper_1.getENV)('ACCESS_TOKEN_AGE', 1));
42
+ if (rf_expire_in < ac_expire_in) {
43
+ ac_expire_in = rf_expire_in;
44
+ }
45
+ let input = Object.assign({ id: refreshTokenUUID, user_id: id, expired_at: (0, helper_1.getDateTime)().add(rf_expire_in, 'days'), token: signToken(id, rf_expire_in, Object.assign({ refresh_token_id: refreshTokenUUID }, include_token)), accessToken: Object.assign({ user_id: id, expired_at: (0, helper_1.getDateTime)().add(ac_expire_in, 'days'), token: signToken(id, ac_expire_in, Object.assign({ refresh_token_id: refreshTokenUUID }, include_token)) }, include_access) }, include);
41
46
  yield refresh_token_1.RefreshTokenModel.schema(this.ref, "_").create(input, {
42
47
  include: [
43
48
  {
package/utils/db.js CHANGED
@@ -32,12 +32,12 @@ const getWhereVal = (smth) => {
32
32
  return [key, value].join(` ${smth.comparator} `);
33
33
  };
34
34
  const genWhere = (where = {}, { as = "", delimiter = ".", prefix = true, bracket = false } = {}) => {
35
- as = as ? as + delimiter : as;
35
+ let keyPrefix = as ? "`" + as + "`" + delimiter : as;
36
36
  let symbolKeys = Object.getOwnPropertySymbols(where);
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 (value) == "string" ? `${as}${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
  }
@@ -48,7 +48,7 @@ const genWhere = (where = {}, { as = "", delimiter = ".", prefix = true, bracket
48
48
  result = `${result}( ${op}) AND `;
49
49
  }
50
50
  else {
51
- result = `${result + key} IN (${value.map(i => "'" + i + "'").join(',')}) AND `;
51
+ result = result + key + ` IN (${value.map(i => "'" + i + "'").join(',')}) AND `;
52
52
  }
53
53
  return result;
54
54
  }
@@ -62,7 +62,7 @@ const genWhere = (where = {}, { as = "", delimiter = ".", prefix = true, bracket
62
62
  return result;
63
63
  }
64
64
  else if (typeof value == "object" && value['val']) {
65
- result = `${result}${key}=${value['val']} AND `;
65
+ result = result + key + `=${value['val']} AND `;
66
66
  return result;
67
67
  }
68
68
  result = result + key + "=" + value + " AND ";
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
@@ -133,6 +133,7 @@ class FileUtil {
133
133
  let reqs = [], results = [];
134
134
  for (let file of files) {
135
135
  let extension = mime.extension(file.mimetype);
136
+ extension = extension ? extension : String(file.mimetype).split('/')[1];
136
137
  let input = {
137
138
  Bucket: this.bucket,
138
139
  Key: this.ref + "/" + (0, helper_1.getDateTime)().format('X') + '.' + (0, helper_1.getSlug)(32) + '.' + extension,
@@ -256,7 +257,7 @@ class FileUtil {
256
257
  result[width + 'x' + height] = thumb;
257
258
  yield (0, db_1.update)(this.ref, file_1.FileModel.getTableName().toString(), { thumb: JSON.stringify(result) }, { where: { id: item['id'] } });
258
259
  }
259
- if (item['filename'] == path) {
260
+ if (thumb && item['filename'] == path) {
260
261
  yield this.getStorage();
261
262
  let data = yield this.afterQueryFile({ filename: thumb, path: thumb });
262
263
  thumb = data.path;
@@ -406,6 +407,7 @@ class FileUtil {
406
407
  let folder = yield this.createFolder(slug, { parent_id, root, name });
407
408
  for (let file of req.files) {
408
409
  let extension = mime.extension(file.mimetype);
410
+ extension = extension ? extension : String(file.mimetype).split('/')[1];
409
411
  let input = {
410
412
  Bucket: this.bucket,
411
413
  Key: this.ref + "/" + (0, helper_1.getDateTime)().format('X') + '.' + (0, helper_1.getSlug)(32) + '.' + extension,
@@ -579,6 +581,7 @@ class FileUtil {
579
581
  path = (index < 0) ? protocol + path : path;
580
582
  }
581
583
  let extension = mime.extension(reqs[key].mimetype);
584
+ extension = extension ? extension : String(reqs[key].mimetype).split('/')[1];
582
585
  let item = Object.assign(Object.assign({}, input), { folder_id,
583
586
  user_id,
584
587
  organ_id,
@@ -639,10 +642,10 @@ class FileUtil {
639
642
  }
640
643
  });
641
644
  }
642
- 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'] } = {}) {
643
646
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
644
647
  let query = yield this.uploadRaw(files);
645
- return yield this.formatFile(0, 0, files, query, { format: true, field });
648
+ return yield this.formatFile(0, 0, files, query, { format, field });
646
649
  });
647
650
  }
648
651
  updateFile(id, input = {}, { paths = [] } = {}) {
package/utils/helper.d.ts CHANGED
@@ -12,6 +12,10 @@ export declare const getDaysBetweenDates: (startDate: any, endDate: any, { utc }
12
12
  }) => any[];
13
13
  export declare const Joi_date: any;
14
14
  export declare const getENV: (str: string, def?: any) => any;
15
+ export declare const getENVIndex: (index: string, { prefix, force }?: {
16
+ prefix?: string;
17
+ force?: boolean;
18
+ }) => string;
15
19
  export declare const getSlug: (length?: number) => string;
16
20
  export declare const getDateMysql: (date?: any) => any;
17
21
  export declare const getTimestampMysql: (date?: any) => number;
@@ -50,6 +54,9 @@ export declare const removeHyphen: (str: string, replace?: string, { encode, rep
50
54
  export declare const getMobileNumber: (str: string, { prefix }?: {
51
55
  prefix?: string;
52
56
  }) => string;
57
+ export declare const formatMobileNumber: (str: string, { prefix }?: {
58
+ prefix?: string;
59
+ }) => string;
53
60
  export declare const removeSpace: (str: string, replace?: string) => string;
54
61
  export declare const removeAt: (str: string, replace?: string) => string;
55
62
  export declare const isNumber: (val: any, { negative }?: {
@@ -89,6 +96,7 @@ export declare const slugify: (string?: any, { lowercase }?: {
89
96
  }) => any;
90
97
  export declare const slugifyField: (string?: any) => any;
91
98
  export declare const stripHtml: (string: string) => string;
99
+ export declare const stripEmoji: (string: string) => string;
92
100
  export declare const replaceColon: (string: string, { decode }?: {
93
101
  decode?: boolean;
94
102
  }) => string;
package/utils/helper.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertCurrency = exports.xorMerge = exports.xorDecode = exports.xorEncode = exports.getInstanceNumber = exports.getDomain = exports.getParent = exports.replaceColon = exports.stripHtml = exports.slugifyField = exports.slugify = exports.convertToBigEndian = exports.expandTree = exports.buildTree = exports.treeToArray = exports.randomRef = exports.multiExecArray = exports.isBase64 = exports.isNumber = exports.removeAt = exports.removeSpace = exports.getMobileNumber = exports.removeHyphen = exports.signToken = exports.getTokenDataFromTokenBySecret = exports.getUUID32 = exports.getUUID = exports.sleep = exports.getValueByLang = exports.getValueFunctionLang = exports.getValueFunctionFile = exports.getDateTime = exports.getTimestampMysql = exports.getDateMysql = exports.getSlug = exports.getENV = exports.Joi_date = exports.getDaysBetweenDates = exports.getDateFromString = exports.getDateRangeFormat = void 0;
3
+ exports.convertCurrency = exports.xorMerge = exports.xorDecode = exports.xorEncode = exports.getInstanceNumber = exports.getDomain = exports.getParent = exports.replaceColon = exports.stripEmoji = exports.stripHtml = exports.slugifyField = exports.slugify = exports.convertToBigEndian = exports.expandTree = exports.buildTree = exports.treeToArray = exports.randomRef = exports.multiExecArray = exports.isBase64 = exports.isNumber = exports.removeAt = exports.removeSpace = exports.formatMobileNumber = exports.getMobileNumber = exports.removeHyphen = exports.signToken = exports.getTokenDataFromTokenBySecret = exports.getUUID32 = exports.getUUID = exports.sleep = exports.getValueByLang = exports.getValueFunctionLang = exports.getValueFunctionFile = exports.getDateTime = exports.getTimestampMysql = exports.getDateMysql = exports.getSlug = exports.getENVIndex = exports.getENV = exports.Joi_date = exports.getDaysBetweenDates = exports.getDateFromString = exports.getDateRangeFormat = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const crypto = require("crypto");
6
6
  const dotenv = require("dotenv");
@@ -57,6 +57,13 @@ const getENV = (str, def) => {
57
57
  return process.env[str] || def;
58
58
  };
59
59
  exports.getENV = getENV;
60
+ const getENVIndex = (index, { prefix = "dev", force = false } = {}) => {
61
+ if (process.env.NODE_ENV == "production" || force) {
62
+ return index;
63
+ }
64
+ return prefix + "_" + index;
65
+ };
66
+ exports.getENVIndex = getENVIndex;
60
67
  const getSlug = (length = 8) => {
61
68
  return new short_unique_id_1.default().randomUUID(length);
62
69
  };
@@ -154,14 +161,25 @@ exports.removeHyphen = removeHyphen;
154
161
  const getMobileNumber = (str, { prefix = "+66" } = {}) => {
155
162
  if (str) {
156
163
  str = str.replace(/_/g, "").replace(/-/g, "").replace(/ /g, "");
157
- if (str.indexOf("+") == -1 && str.length == 10) {
158
- str = str.substr(1);
164
+ if (str.indexOf("+") == -1 && (str.length == 10 || str.length == 9)) {
165
+ if (str.length == 10 && str[0] == "0")
166
+ str = str.substr(1);
159
167
  str = prefix + str;
160
168
  }
161
169
  }
162
170
  return str;
163
171
  };
164
172
  exports.getMobileNumber = getMobileNumber;
173
+ const formatMobileNumber = (str, { prefix = "+66" } = {}) => {
174
+ if (str) {
175
+ str = str.replace(/_/g, "").replace(/-/g, "").replace(/ /g, "").replace(prefix, "");
176
+ if (str.length == 9) {
177
+ str = "0" + str;
178
+ }
179
+ }
180
+ return str;
181
+ };
182
+ exports.formatMobileNumber = formatMobileNumber;
165
183
  const removeSpace = (str, replace = "") => {
166
184
  return str ? str.replace(/ /g, replace) : "";
167
185
  };
@@ -355,6 +373,10 @@ const stripHtml = (string) => {
355
373
  .replace(/\n/g, '');
356
374
  };
357
375
  exports.stripHtml = stripHtml;
376
+ const stripEmoji = (string) => {
377
+ return String(string).replace(/(?![*#0-9]+)[\p{Emoji}\p{Emoji_Modifier}\p{Emoji_Component}\p{Emoji_Modifier_Base}\p{Emoji_Presentation}]/gu, '').trim();
378
+ };
379
+ exports.stripEmoji = stripEmoji;
358
380
  const replaceColon = (string, { decode = false } = {}) => {
359
381
  if (!string || typeof (string) != 'string') {
360
382
  return string;
package/utils/metadata.js CHANGED
@@ -27,11 +27,11 @@ class MetadataUtil {
27
27
  let value = {}, type = types;
28
28
  if (_.isObject(input[key])) {
29
29
  let val = {};
30
- _.each(input[key], (v, k) => { val['value_' + k] = (0, helper_1.stripHtml)(v ? v.substring(0, str_length) : ""); });
30
+ _.each(input[key], (v, k) => { val['value_' + k] = v ? (0, helper_1.stripEmoji)((0, helper_1.stripHtml)(v)).substring(0, str_length) : ""; });
31
31
  value = val;
32
32
  }
33
33
  else {
34
- value = { value_en: (0, helper_1.stripHtml)(String(input[key] || "").substring(0, str_length)) };
34
+ value = { value_en: (0, helper_1.stripEmoji)((0, helper_1.stripHtml)(String(input[key] || "")).substring(0, str_length)) };
35
35
  }
36
36
  if (autoType && !items[key]) {
37
37
  let str = key.split(":");
package/utils/stream.d.ts CHANGED
@@ -170,6 +170,14 @@ export declare class StreamUtil {
170
170
  tags?: TagFile;
171
171
  group?: any;
172
172
  }): Promise<{}>;
173
+ upsertBySlugField(fields: Array<any>, index: string, { ref, req, parent_slug, input, tags, group }?: {
174
+ ref?: string;
175
+ req?: Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
176
+ parent_slug?: string;
177
+ input?: {};
178
+ tags?: TagFile;
179
+ group?: any;
180
+ }): Promise<{}>;
173
181
  findStream(slug: string, namespace: string, { result, lang_code, field_exclude, multiple, relationship, file, image, is_lang, stream, use_param }?: {
174
182
  result?: any[];
175
183
  lang_code?: string;
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 } });
@@ -938,7 +938,14 @@ class StreamUtil {
938
938
  }
939
939
  upsertBySlug(slug, namespace, index, { ref = "", req = {}, parent_slug = "", input = {}, tags = [], group = undefined } = {}) {
940
940
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
941
- let fields = yield this.getBuilder(slug, namespace, { index: "fields" }), where_folder = {};
941
+ let fields = yield this.getBuilder(slug, namespace, { index: "fields" });
942
+ return yield this.upsertBySlugField(fields, index, { ref, req, parent_slug, input, tags, group });
943
+ });
944
+ }
945
+ upsertBySlugField(fields, index, { ref = "", req = {}, parent_slug = "", input = {}, tags = [], group = undefined } = {}) {
946
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
947
+ fields = fields || [];
948
+ let where_folder = {};
942
949
  ref = ref || this.ref;
943
950
  let files = (req.file ? [req.file] : (req.files || [])).reduce((total, item) => Object.assign(total, { [item['fieldname']]: item }), {});
944
951
  let id_files = {}, fileUtil = new file_2.FileUtil(ref, this.option);
@@ -1925,11 +1932,13 @@ class StreamUtil {
1925
1932
  allow_type = new RegExp(/^(image.*)$/).test(file[field_slug]['mimetype']);
1926
1933
  if (!allow_type) {
1927
1934
  input[field_slug] = mime.extension(file[field_slug]['mimetype']);
1935
+ input[field_slug] = input[field_slug] ? input[field_slug] : String(file[field_slug]['mimetype']).split('/')[1];
1928
1936
  field = Joi.string().valid('image/*');
1929
1937
  }
1930
1938
  }
1931
1939
  if (!allow_type && field_data['allowed_types']) {
1932
1940
  let extension = String(mime.extension(file[field_slug]['mimetype']));
1941
+ extension = extension ? extension : String(file[field_slug]['mimetype']).split('/')[1];
1933
1942
  if (!new RegExp(`^(${field_data['allowed_types']})$`).test(extension)) {
1934
1943
  input[field_slug] = extension;
1935
1944
  field = Joi.string().valid(...(field_data['allowed_types'].split('|') || []));
package/utils/user.d.ts CHANGED
@@ -40,9 +40,9 @@ export declare const convertAddress: (data: any, { lang_code, transform }?: {
40
40
  lang_code?: string;
41
41
  transform?: boolean;
42
42
  }) => Promise<any>;
43
- export declare const getAddressIndex: (data: any, { condition, lang_code }?: {
43
+ export declare const getAddressIndex: (data: any, { condition, where }?: {
44
44
  condition?: {};
45
- lang_code?: string;
45
+ where?: {};
46
46
  }) => Promise<{}>;
47
47
  export declare const getCountry: (ref: string, { organ_id, lang_code, setting }?: {
48
48
  organ_id?: string;
package/utils/user.js CHANGED
@@ -229,12 +229,11 @@ const convertAddress = (data, { lang_code = "en", transform = false } = {}) => t
229
229
  return data;
230
230
  });
231
231
  exports.convertAddress = convertAddress;
232
- const getAddressIndex = (data, { condition = {}, lang_code = "en" } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
233
- let result = {}, where = { lang_code: [lang_code, "en"] }, bol = false;
234
- let order = [sequelize.literal(`FIELD(lang_code,${'\'' + where['lang_code'].join('\',\'') + '\''})`)];
232
+ const getAddressIndex = (data, { condition = {}, where = {} } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
233
+ let result = {}, bol = false;
235
234
  if (!bol && data['country'] && !condition['country_id']) {
236
235
  let country = yield country_1.CountryModel.schema("core", "_").findOne({
237
- raw: true, where: Object.assign(Object.assign({}, where), { country_name: data['country'] }), attributes: ['id'], order
236
+ raw: true, where: Object.assign(Object.assign({}, where), { country_name: data['country'] }), attributes: ['id']
238
237
  });
239
238
  if (country) {
240
239
  result['country_id'] = country['id'];
@@ -245,7 +244,7 @@ const getAddressIndex = (data, { condition = {}, lang_code = "en" } = {}) => tsl
245
244
  if (!bol && data['state'] && !condition['state_id']) {
246
245
  let country_id = condition['country_id'] || null;
247
246
  let state = yield state_1.StateModel.schema("core", "_").findOne({
248
- raw: true, where: Object.assign(Object.assign({}, where), { country_id, state_name: data['state'] }), attributes: ['id'], order
247
+ raw: true, where: Object.assign(Object.assign({}, where), { country_id, state_name: data['state'] }), attributes: ['id']
249
248
  });
250
249
  if (state) {
251
250
  result['state_id'] = state['id'];
@@ -256,7 +255,7 @@ const getAddressIndex = (data, { condition = {}, lang_code = "en" } = {}) => tsl
256
255
  if (!bol && data['city'] && !condition['city_id']) {
257
256
  let state_id = condition['state_id'] || null;
258
257
  let city = yield city_1.CityModel.schema("core", "_").findOne({
259
- raw: true, where: Object.assign(Object.assign({}, where), { state_id, city_name: data['city'] }), attributes: ['id'], order
258
+ raw: true, where: Object.assign(Object.assign({}, where), { state_id, city_name: data['city'] }), attributes: ['id']
260
259
  });
261
260
  if (city) {
262
261
  result['city_id'] = city['id'];
@@ -267,7 +266,7 @@ const getAddressIndex = (data, { condition = {}, lang_code = "en" } = {}) => tsl
267
266
  if (!bol && data['district']) {
268
267
  let city_id = condition['city_id'] || null;
269
268
  let district = yield district_1.DistrictModel.schema("core", "_").findOne({
270
- raw: true, where: Object.assign(Object.assign({}, where), { city_id, district_name: data['district'] }), attributes: ['id'], order
269
+ raw: true, where: Object.assign(Object.assign({}, where), { city_id, district_name: data['district'] }), attributes: ['id']
271
270
  });
272
271
  if (district)
273
272
  result['district_id'] = district['id'];
@@ -318,9 +317,12 @@ const getGroupSetting = (ref, id, { attributes = ['id', 'shared', 'setting'] } =
318
317
  exports.getGroupSetting = getGroupSetting;
319
318
  const getGroupPermission = (ref, id, module, { permission = {}, group_shared = undefined, organ_id = 0, attributes = ['id', 'shared', 'setting'] } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
320
319
  if (typeof group_shared == "undefined") {
321
- let setting = yield (0, exports.getGroupSetting)(ref, id, { attributes });
322
- if (setting)
323
- group_shared = setting['shared'];
320
+ let group = yield (0, exports.getGroupSetting)(ref, id, { attributes });
321
+ if (group) {
322
+ permission['group_setting'] = group['setting'] || {};
323
+ permission['admin'] = group['shared'];
324
+ group_shared = group['shared'];
325
+ }
324
326
  }
325
327
  if (typeof group_shared != "undefined" && group_shared == 0) {
326
328
  let query = yield group_permission_1.UserGroupPermissionModel.schema(ref, "_").findOne({
@@ -105,7 +105,7 @@ const fileService = (setup, { userfiles = false, required = false, fileSize = 0,
105
105
  let option = setup(validate);
106
106
  let upload = userfiles ? option.array("userfiles", maxCount) : option.any();
107
107
  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())(req, res, () => 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
109
  try {
110
110
  let field = userfiles ? "userfiles" : undefined;
111
111
  if (err) {
@@ -180,7 +180,7 @@ const multiService = ({ field = undefined, record = undefined, record_addition =
180
180
  schema['field'] = Joi.string().valid(...field);
181
181
  schema['value'] = value_schema;
182
182
  }
183
- return (0, exports.validateService)(Joi.object().keys(Object.assign(Object.assign({}, schema), { records: Joi.array().items(Joi.object().keys(Object.assign({ id: Joi.number().required() }, record)).options({ stripUnknown: true })).min(1).required() })).options({ stripUnknown: true }));
183
+ return (0, exports.validateService)(Joi.object().keys(Object.assign(Object.assign({}, schema), { records: Joi.array().items(Joi.object().keys(Object.assign({ id: Joi.number().required() }, record)).options({ stripUnknown: true })).min(1).required() })).options({ stripUnknown: true }), { field_omit: [] });
184
184
  };
185
185
  exports.multiService = multiService;
186
186
  const streamService = ({ slug = "", name_space = "", param = "index" } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
@@ -207,7 +207,7 @@ const streamService = ({ slug = "", name_space = "", param = "index" } = {}) =>
207
207
  });
208
208
  exports.streamService = streamService;
209
209
  const importService = ({ import_type = [], schema = {} } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
210
- return (0, exports.validateService)(Joi.object().keys(Object.assign({ import_type: Joi.string().valid(...import_type) }, schema)).unknown())(req, res, next);
210
+ return (0, exports.validateService)(Joi.object().keys(Object.assign({ import_type: Joi.string().valid(...import_type) }, schema)).unknown(), { field_omit: [] })(req, res, next);
211
211
  });
212
212
  exports.importService = importService;
213
213
  const exportService = ({ file_type = undefined, export_type = [], limit = 200, schema = {} } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
@@ -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['maxQueryIds'] || 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['maxQueryIds'] || 25)) });
266
268
  }
267
269
  let option = Object.keys(schema || {});
268
270
  if (option.length) {
@@ -288,11 +290,11 @@ const fieldService = ({ field = [], schema = {} } = {}) => (req, res, next) => t
288
290
  });
289
291
  exports.fieldService = fieldService;
290
292
  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);
293
+ 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(), { field_omit: [] })(req, res, next);
292
294
  });
293
295
  exports.convertService = convertService;
294
296
  const entryValidateService = ({ module = ['contact'], schema = {} } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
295
- return (0, exports.validateService)(Joi.object().keys(Object.assign({ module: Joi.string().valid(...module), entry_id: Joi.number().required() }, schema)).unknown())(req, res, next);
297
+ return (0, exports.validateService)(Joi.object().keys(Object.assign({ module: Joi.string().valid(...module), entry_id: Joi.number().required() }, schema)).unknown(), { field_omit: [] })(req, res, next);
296
298
  });
297
299
  exports.entryValidateService = entryValidateService;
298
300
  const entryParamService = ({ module = ['contact'], schema = {} } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {