@digione/node-custom-api 0.1.8-beta2 → 0.1.9-alpha7

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.
@@ -90,6 +90,7 @@ export declare const FileAttr: {
90
90
  upload: sequelize.TinyIntegerDataType;
91
91
  custom: sequelize.AbstractDataTypeConstructor;
92
92
  tags: sequelize.AbstractDataTypeConstructor;
93
+ group: sequelize.StringDataType;
93
94
  file_link: sequelize.EnumDataType<"no" | "yes">;
94
95
  file_id: sequelize.StringDataType;
95
96
  uid: sequelize.StringDataType;
@@ -95,6 +95,7 @@ exports.FileAttr = {
95
95
  upload: sequelize.TINYINT({ length: 1 }),
96
96
  custom: sequelize.JSON,
97
97
  tags: sequelize.JSON,
98
+ group: sequelize.STRING({ length: 20 }),
98
99
  file_link: sequelize.ENUM('no', 'yes'),
99
100
  file_id: sequelize.STRING({ length: 15 }),
100
101
  uid: sequelize.STRING({ length: 100 })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digione/node-custom-api",
3
- "version": "0.1.8-beta2",
3
+ "version": "0.1.9-alpha7",
4
4
  "description": "Typescript node digione-api",
5
5
  "author": "Monchai Jirayupong <monchai.j@seven.co.th>",
6
6
  "license": "MIT",
package/utils/file.d.ts CHANGED
@@ -124,11 +124,12 @@ export declare class FileUtil {
124
124
  tags?: TagFile;
125
125
  group?: any;
126
126
  }): Promise<any>;
127
- uploadByReq(req: Request, slug: string, user_id: any, { parent_id, parent_slug, name, root, thumb, width, height, input, is_hidden, tags, group }?: {
127
+ uploadByReq(req: Request, slug: string, user_id: any, { parent_id, parent_slug, name, root, format, thumb, width, height, input, is_hidden, tags, group }?: {
128
128
  parent_id?: number;
129
129
  parent_slug?: string;
130
130
  name?: any;
131
131
  root?: boolean;
132
+ format?: boolean;
132
133
  thumb?: boolean;
133
134
  width?: number;
134
135
  height?: number;
@@ -146,7 +147,7 @@ export declare class FileUtil {
146
147
  hidden?: number;
147
148
  input?: {};
148
149
  }): Promise<any>;
149
- createFileByPath(files: Array<string>, slug: string, user_id: any, { parent_slug, type, name, root, upload, tags, group }?: {
150
+ createFileByPath(files: Array<any>, slug: string, user_id: any, { parent_slug, type, name, root, upload, tags, group }?: {
150
151
  parent_slug?: string;
151
152
  type?: string;
152
153
  name?: any;
@@ -156,7 +157,8 @@ export declare class FileUtil {
156
157
  group?: any;
157
158
  }): Promise<any>;
158
159
  allowedFileType(extension: any): Promise<any>;
159
- formatFile(folder_id: any, user_id: any, reqs: Array<any>, files: Array<any>, { use_id, field, formatDateTime, input, is_hidden, tags, group }?: {
160
+ formatFile(folder_id: any, user_id: any, reqs: Array<any>, files: Array<any>, { format, use_id, field, formatDateTime, input, is_hidden, tags, group }?: {
161
+ format?: boolean;
160
162
  use_id?: boolean;
161
163
  field?: any[];
162
164
  formatDateTime?: string;
@@ -169,7 +171,7 @@ export declare class FileUtil {
169
171
  user_id: any;
170
172
  organ_id: any;
171
173
  organ_by: any;
172
- sort: string;
174
+ sort: any;
173
175
  date_added: string;
174
176
  name: any;
175
177
  filename: any;
@@ -179,10 +181,12 @@ export declare class FileUtil {
179
181
  extension: string;
180
182
  type: any;
181
183
  is_hidden: any;
182
- tags: TagFile;
184
+ tags: any;
185
+ custom: any;
183
186
  group: any;
184
187
  }[]>;
185
- insertFileUnique(results: Array<any>, { thumb, width, height }?: {
188
+ insertFileUnique(results: Array<any>, { format, thumb, width, height }?: {
189
+ format?: boolean;
186
190
  thumb?: boolean;
187
191
  width?: number;
188
192
  height?: number;
package/utils/file.js CHANGED
@@ -256,7 +256,7 @@ class FileUtil {
256
256
  result[width + 'x' + height] = thumb;
257
257
  yield (0, db_1.update)(this.ref, file_1.FileModel.getTableName().toString(), { thumb: JSON.stringify(result) }, { where: { id: item['id'] } });
258
258
  }
259
- if (item['filename'] == path) {
259
+ if (thumb && item['filename'] == path) {
260
260
  yield this.getStorage();
261
261
  let data = yield this.afterQueryFile({ filename: thumb, path: thumb });
262
262
  thumb = data.path;
@@ -392,7 +392,7 @@ class FileUtil {
392
392
  return (yield this.findAllFile({ where: Object.assign({ id }, where), full, file_link, parent_folder, limit: 1, tags, group }))[0] || null;
393
393
  });
394
394
  }
395
- uploadByReq(req, slug, user_id, { parent_id = 0, parent_slug = "", name = undefined, root = false, thumb = false, width = 0, height = 0, input = {}, is_hidden = undefined, tags = undefined, group = undefined } = {}) {
395
+ uploadByReq(req, slug, user_id, { parent_id = 0, parent_slug = "", name = undefined, root = false, format = false, thumb = false, width = 0, height = 0, input = {}, is_hidden = undefined, tags = undefined, group = undefined } = {}) {
396
396
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
397
397
  req.files = req.file ? [req.file] : (req.files || []);
398
398
  if (req.files.length && slug) {
@@ -419,7 +419,7 @@ class FileUtil {
419
419
  }
420
420
  let results = yield this.upload(files);
421
421
  results = yield this.formatFile(folder['id'], user_id, reqs, results, { input, is_hidden, tags, group });
422
- return yield this.insertFileUnique(results, { thumb, width, height });
422
+ return yield this.insertFileUnique(results, { format, thumb, width, height });
423
423
  }
424
424
  return Promise.reject(errors_1.generalError.BAD_REQUEST);
425
425
  });
@@ -470,8 +470,13 @@ class FileUtil {
470
470
  let folder = yield this.createFolder(slug, { parent_id, root, name });
471
471
  let results = [], reqs = [];
472
472
  files.forEach((item) => {
473
- results.push({ Location: item, Key: item });
474
- reqs.push({ originalname: (0, helper_1.getSlug)(32), mimetype: null, size: 0, type });
473
+ let addition = {}, path = item;
474
+ if (typeof item == "object") {
475
+ addition = item;
476
+ path = item['path'];
477
+ }
478
+ results.push({ Location: path, Key: path });
479
+ reqs.push(Object.assign({ originalname: (0, helper_1.getSlug)(32), mimetype: null, size: 0, type }, addition));
475
480
  });
476
481
  results = yield this.formatFile(folder['id'], user_id, reqs, results, { input, tags, group });
477
482
  return yield this.insertFileUnique(results);
@@ -557,7 +562,7 @@ class FileUtil {
557
562
  return type;
558
563
  });
559
564
  }
560
- formatFile(folder_id, user_id, reqs, files, { use_id = true, field = [], formatDateTime = "X", input = {}, is_hidden = undefined, tags = undefined, group = undefined } = {}) {
565
+ formatFile(folder_id, user_id, reqs, files, { format = false, use_id = true, field = [], formatDateTime = "X", input = {}, is_hidden = undefined, tags = undefined, group = undefined } = {}) {
561
566
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
562
567
  try {
563
568
  let result = yield Promise.all(files.map((file, key) => tslib_1.__awaiter(this, void 0, void 0, function* () {
@@ -574,30 +579,29 @@ class FileUtil {
574
579
  path = (index < 0) ? protocol + path : path;
575
580
  }
576
581
  let extension = mime.extension(reqs[key].mimetype);
577
- let format = Object.assign(Object.assign({}, input), { folder_id,
582
+ let item = Object.assign(Object.assign({}, input), { folder_id,
578
583
  user_id,
579
584
  organ_id,
580
- organ_by,
581
- sort,
582
- date_added, name: reqs[key].originalname || (0, helper_1.getSlug)(32), filename: reqs[key].Key || file.Key || input['filename'], path, mimetype: reqs[key].mimetype, filesize: reqs[key].size, extension: (extension ? "." + extension : ''), type: reqs[key].type || file.type || input['type'], is_hidden,
583
- tags,
584
- group });
585
+ organ_by, sort: reqs[key].sort || sort, date_added, name: reqs[key].originalname || (0, helper_1.getSlug)(32), filename: reqs[key].Key || file.Key || input['filename'], path, mimetype: reqs[key].mimetype, filesize: reqs[key].size, extension: (extension ? "." + extension : ''), type: reqs[key].type || file.type || input['type'], is_hidden, tags: reqs[key].tags || tags, custom: reqs[key].custom || input['custom'], group });
586
+ if (format) {
587
+ item = yield this.afterQueryFile(item);
588
+ }
585
589
  if (use_id) {
586
- format['id'] = id;
590
+ item['id'] = id;
587
591
  }
588
592
  if (reqs[key].mimetype && reqs[key].mimetype.split('/')[0] == "image") {
589
593
  try {
590
594
  let body = reqs[key].Body || reqs[key].buffer;
591
595
  let image = yield jimp.read(body);
592
- format['height'] = image.bitmap.height;
593
- format['width'] = image.bitmap.width;
596
+ item['height'] = image.bitmap.height;
597
+ item['width'] = image.bitmap.width;
594
598
  }
595
599
  catch (err) { }
596
600
  }
597
601
  if (field.length) {
598
- format = _.pick(format, field);
602
+ item = _.pick(item, field);
599
603
  }
600
- return format;
604
+ return item;
601
605
  })));
602
606
  return result;
603
607
  }
@@ -606,7 +610,7 @@ class FileUtil {
606
610
  }
607
611
  });
608
612
  }
609
- insertFileUnique(results, { thumb = false, width = 0, height = 0 } = {}) {
613
+ insertFileUnique(results, { format = false, thumb = false, width = 0, height = 0 } = {}) {
610
614
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
611
615
  try {
612
616
  let data = yield file_1.FileModel.schema(this.ref, "_").bulkCreate(results);
@@ -614,15 +618,14 @@ class FileUtil {
614
618
  return Promise.reject(errors_1.generalError.BAD_REQUEST);
615
619
  }
616
620
  let result = data.map(item => item.toJSON());
617
- if (thumb) {
618
- // create thumb
621
+ if (format || thumb) {
622
+ // format or create thumb
619
623
  result = yield Promise.all(result.map((item) => tslib_1.__awaiter(this, void 0, void 0, function* () {
620
- if (item['type'] == 'i') {
621
- item['thumb'] = null;
622
- let thumb = yield this.findImageThumb(item, { width, height });
623
- return Object.assign(Object.assign({}, item), { thumb });
624
+ let include = (yield this.afterQueryFile(item)) || {};
625
+ if (thumb && item['type'] == 'i') {
626
+ include['thumb'] = yield this.findImageThumb(item, { width, height });
624
627
  }
625
- return item;
628
+ return Object.assign(Object.assign({}, item), include);
626
629
  })));
627
630
  }
628
631
  return result;
@@ -630,7 +633,7 @@ class FileUtil {
630
633
  catch (err) {
631
634
  if (err.errors && err.errors[0].validatorKey == "not_unique") {
632
635
  results = results.map(item => (Object.assign(Object.assign({}, item), { id: (0, uuid_1.v4)().replace(/-/gi, '').substring(0, 15) })));
633
- return yield this.insertFileUnique(results, { thumb, width, height });
636
+ return yield this.insertFileUnique(results, { format, thumb, width, height });
634
637
  }
635
638
  return Promise.reject(errors_1.generalError.BAD_REQUEST);
636
639
  }
@@ -639,7 +642,7 @@ class FileUtil {
639
642
  uploadRawFormat(files, { field = ['name', 'filename', 'path', 'mimetype', 'filesize', 'extension', 'type', 'height', 'width'] } = {}) {
640
643
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
641
644
  let query = yield this.uploadRaw(files);
642
- return yield this.formatFile(0, 0, files, query, { field });
645
+ return yield this.formatFile(0, 0, files, query, { format: true, field });
643
646
  });
644
647
  }
645
648
  updateFile(id, input = {}, { paths = [] } = {}) {
package/utils/helper.d.ts CHANGED
@@ -64,7 +64,7 @@ export declare const randomRef: ({ length_digital, length_alphabet }?: {
64
64
  length_alphabet?: number;
65
65
  }) => string;
66
66
  export declare const treeToArray: (items: Array<any>, array?: Array<any>, level?: number) => Promise<any[]>;
67
- export declare const buildTree: (nodes: Array<any>, { index, field_children, json_convert, key_index, key_parent, root, to_array }?: {
67
+ export declare const buildTree: (nodes: Array<any>, { index, field_children, json_convert, key_index, key_parent, root, to_array, notfound_parent }?: {
68
68
  index?: any;
69
69
  field_children?: string;
70
70
  json_convert?: boolean;
@@ -72,6 +72,7 @@ export declare const buildTree: (nodes: Array<any>, { index, field_children, jso
72
72
  key_parent?: string;
73
73
  root?: any;
74
74
  to_array?: boolean;
75
+ notfound_parent?: boolean;
75
76
  }) => Promise<any[]>;
76
77
  export declare const expandTree: (items: Array<any>, { array, parent, level, prefix, field_index, field_children, key_value }?: {
77
78
  array?: any[];
package/utils/helper.js CHANGED
@@ -228,7 +228,7 @@ const treeToArray = (items, array = [], level = 1) => tslib_1.__awaiter(void 0,
228
228
  return array;
229
229
  });
230
230
  exports.treeToArray = treeToArray;
231
- const buildTree = (nodes, { index = undefined, field_children = "children", json_convert = false, key_index = "id", key_parent = "parent", root = undefined, to_array = false } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
231
+ const buildTree = (nodes, { index = undefined, field_children = "children", json_convert = false, key_index = "id", key_parent = "parent", root = undefined, to_array = false, notfound_parent = false } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
232
232
  if (!nodes) {
233
233
  return null;
234
234
  }
@@ -266,11 +266,16 @@ const buildTree = (nodes, { index = undefined, field_children = "children", json
266
266
  }
267
267
  }
268
268
  parent[field_children] = results;
269
+ delete children[parent[key_index]];
269
270
  }
270
271
  };
271
272
  for (let i = 0, len = roots.length; i < len; ++i) {
272
273
  findChildren(roots[i]);
273
274
  }
275
+ if (notfound_parent) {
276
+ let items = Object.keys(children).reduce((total, key) => total.concat(children[key]), []);
277
+ roots.unshift({ [key_index]: -1, [field_children]: items });
278
+ }
274
279
  if (index)
275
280
  roots = roots[0];
276
281
  if (roots && to_array) {
package/utils/stream.d.ts CHANGED
@@ -40,7 +40,7 @@ export declare class StreamUtil {
40
40
  private fileUtil;
41
41
  private languageUtil;
42
42
  constructor(ref?: string, option?: QueryParamOption, fileUtil?: FileUtil);
43
- findField(slug: string, namespace: string, { index, option, no_lang, field_slug, field_only, field_required, lang, lang_code, is_required, default_value, addition, include, include_only, convert_option, field_option, require, multiple_table, multiple_spread, text, bullets, multiple, relationship, file, image, field_exclude, section }?: {
43
+ findField(slug: string, namespace: string, { index, option, no_lang, field_slug, field_only, field_required, lang, lang_code, is_required, default_value, addition, include, include_only, convert_option, convert_value, field_option, require, multiple_table, multiple_spread, text, bullets, multiple, relationship, file, image, field_exclude, section }?: {
44
44
  index?: string;
45
45
  option?: {};
46
46
  no_lang?: boolean;
@@ -55,6 +55,7 @@ export declare class StreamUtil {
55
55
  include?: any;
56
56
  include_only?: boolean;
57
57
  convert_option?: boolean;
58
+ convert_value?: boolean;
58
59
  field_option?: {};
59
60
  require?: boolean;
60
61
  multiple_table?: boolean;
@@ -117,7 +118,7 @@ export declare class StreamUtil {
117
118
  result: {};
118
119
  labels: any[];
119
120
  }>;
120
- genField(streams: Array<any>, { index, option, slug, id_stream, prefix, multiple_table, multiple_spread, addition, convert_option, field_option, default_value, default_lang, lang_code, no_lang, lang, country, section }?: {
121
+ genField(streams: Array<any>, { index, option, slug, id_stream, prefix, multiple_table, multiple_spread, addition, convert_option, convert_value, field_option, default_value, default_lang, lang_code, no_lang, lang, country, section }?: {
121
122
  index?: string;
122
123
  option?: {};
123
124
  slug?: string;
@@ -127,6 +128,7 @@ export declare class StreamUtil {
127
128
  multiple_spread?: boolean;
128
129
  addition?: {};
129
130
  convert_option?: boolean;
131
+ convert_value?: boolean;
130
132
  field_option?: {};
131
133
  default_value?: any;
132
134
  default_lang?: string;
package/utils/stream.js CHANGED
@@ -101,7 +101,7 @@ class StreamUtil {
101
101
  this.fileUtil = fileUtil || new file_2.FileUtil(this.ref, this.option);
102
102
  this.languageUtil = new language_1.LanguageUtil(this.ref, this.option);
103
103
  }
104
- findField(slug, namespace, { index = "", option = {}, no_lang = false, field_slug = [], field_only = true, field_required = true, lang = [], lang_code = "en", is_required = "", default_value = {}, addition = {}, include = undefined, include_only = false, convert_option = false, field_option = {}, require = false, multiple_table = false, multiple_spread = false, text = false, bullets = false, multiple = false, relationship = false, file = false, image = false, field_exclude = [], section = false } = {}) {
104
+ findField(slug, namespace, { index = "", option = {}, no_lang = false, field_slug = [], field_only = true, field_required = true, lang = [], lang_code = "en", is_required = "", default_value = {}, addition = {}, include = undefined, include_only = false, convert_option = false, convert_value = false, field_option = {}, require = false, multiple_table = false, multiple_spread = false, text = false, bullets = false, multiple = false, relationship = false, file = false, image = false, field_exclude = [], section = false } = {}) {
105
105
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
106
106
  let data;
107
107
  let where = {};
@@ -184,7 +184,7 @@ class StreamUtil {
184
184
  }
185
185
  }
186
186
  if (convert_option) {
187
- data['fields'] = yield this.genField(data['fields'], { index, option, slug, id_stream: data['id'], prefix: data['stream_prefix'], multiple_table, multiple_spread, addition, field_option, default_value, lang_code, no_lang, lang, section });
187
+ data['fields'] = yield this.genField(data['fields'], { index, option, slug, id_stream: data['id'], prefix: data['stream_prefix'], multiple_table, multiple_spread, addition, convert_value, field_option, default_value, lang_code, no_lang, lang, section });
188
188
  }
189
189
  if (field_only) {
190
190
  return data['fields'];
@@ -289,7 +289,7 @@ class StreamUtil {
289
289
  }
290
290
  }
291
291
  }
292
- if (field['field_type'] == "multiple" || field['field_type'] == "any") {
292
+ if ((field['field_type'] == "multiple" && field_data['self_table'] != "yes") || field['field_type'] == "any") {
293
293
  delete attributes[field['field_slug']];
294
294
  }
295
295
  }
@@ -347,7 +347,7 @@ class StreamUtil {
347
347
  return { result, labels };
348
348
  });
349
349
  }
350
- genField(streams, { index = "", option = {}, slug = "", id_stream = "", prefix = "", multiple_table = false, multiple_spread = false, addition = {}, convert_option = true, field_option = {}, default_value = {}, default_lang = "en", lang_code = "en", no_lang = false, lang = [], country = undefined, section = false } = {}) {
350
+ genField(streams, { index = "", option = {}, slug = "", id_stream = "", prefix = "", multiple_table = false, multiple_spread = false, addition = {}, convert_option = true, convert_value = false, field_option = {}, default_value = {}, default_lang = "en", lang_code = "en", no_lang = false, lang = [], country = undefined, section = false } = {}) {
351
351
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
352
352
  let fields = [], sections = [];
353
353
  let exclude = option['excludeObj'] || {};
@@ -472,7 +472,9 @@ class StreamUtil {
472
472
  continue;
473
473
  }
474
474
  if (convert_option) {
475
+ let obj_value = {};
475
476
  if (item['field_type'] == "choice") {
477
+ let opt_empty = false;
476
478
  if (field_data['choice_data']) {
477
479
  let data = [];
478
480
  data = field_data['choice_data'].split('\n');
@@ -495,12 +497,16 @@ class StreamUtil {
495
497
  data[k] = { key, value };
496
498
  }
497
499
  else {
500
+ opt_empty = true;
498
501
  data[k] = { key: '', value };
499
502
  }
500
503
  }
501
504
  else {
502
505
  data[k] = { key: v, value: v };
503
506
  }
507
+ if (convert_value && data[k]) {
508
+ obj_value[data[k]['key']] = data[k]['value'];
509
+ }
504
510
  });
505
511
  item['data'] = data;
506
512
  }
@@ -510,9 +516,23 @@ class StreamUtil {
510
516
  if (value && value.indexOf('lang:') > -1) {
511
517
  item['value'] = (0, i18n_1.__)({ phrase: value, locale: lang_code });
512
518
  }
519
+ if (!item['key'])
520
+ opt_empty = true;
521
+ if (convert_value && item['key']) {
522
+ obj_value[item['key']] = item['value'];
523
+ }
513
524
  return item;
514
525
  });
515
526
  }
527
+ if (field_data['default_value'] && !opt_empty && (item['field_value'] == '' || item['field_value'] == null)) {
528
+ item['field_value'] = field_data['default_value'];
529
+ }
530
+ if (convert_value && typeof item['field_value'] != "undefined") {
531
+ let field_value = item['field_value'];
532
+ if (item['field_value'] == null && opt_empty)
533
+ field_value = '';
534
+ field_data['value'] = obj_value[field_value];
535
+ }
516
536
  }
517
537
  else if (!field_option[item['field_slug']] && (item['field_type'] == "relationship" || item['field_type'] == "multiple") && field_data['choose_stream']) {
518
538
  try {
@@ -557,6 +577,9 @@ class StreamUtil {
557
577
  item['title'] = item['title'] ? item['title'] : item[stream['title_column']];
558
578
  (0, helper_2.getValueFunctionLang)('title')(item, { result: item, lang_code });
559
579
  let value = item['title'] ? item['title'] : item['id'];
580
+ if (convert_value && item['id']) {
581
+ obj_value[item['id']] = value;
582
+ }
560
583
  return {
561
584
  key: item['id'],
562
585
  value
@@ -567,6 +590,9 @@ class StreamUtil {
567
590
  }
568
591
  }
569
592
  item['data'] = data;
593
+ if (convert_value && item['field_value']) {
594
+ field_data['value'] = obj_value[item['field_value']];
595
+ }
570
596
  }
571
597
  catch (err) { }
572
598
  }
@@ -1636,8 +1662,10 @@ class StreamUtil {
1636
1662
  }
1637
1663
  }
1638
1664
  }
1639
- let sort_order = yield field_1.FieldModel.schema(this.ref, "_").max('sort_order', { where: { stream_id: stream['id'] } });
1640
- field['sort_order'] = sort_order ? Number(sort_order + 1) : 1;
1665
+ if (typeof field['sort_order'] == "undefined") {
1666
+ let sort_order = yield field_1.FieldModel.schema(this.ref, "_").max('sort_order', { where: { stream_id: stream['id'] } });
1667
+ field['sort_order'] = sort_order ? Number(sort_order + 1) : 1;
1668
+ }
1641
1669
  if (!field['stream_id']) {
1642
1670
  field['stream_id'] = stream['id'];
1643
1671
  }
package/utils/user.js CHANGED
@@ -277,7 +277,14 @@ const getAddressIndex = (data, { condition = {}, lang_code = "en" } = {}) => tsl
277
277
  exports.getAddressIndex = getAddressIndex;
278
278
  const getCountry = (ref, { organ_id = "", lang_code = "en", setting = {} } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
279
279
  let where = { status: 1, lang_code }, default_country;
280
- if (setting['country_id']) {
280
+ if (organ_id) {
281
+ let query = yield organ_1.UserOrganModel.schema(ref, "_").findOne({ where: { id: organ_id }, attributes: ['setting'], raw: true });
282
+ setting = query ? (query['setting'] || {}) : {};
283
+ }
284
+ if (setting['mobile_code']) {
285
+ where['mobilecode'] = setting['mobile_code'].split(",");
286
+ }
287
+ else if (setting['country_id']) {
281
288
  where['id'] = setting['country_id'].split(",");
282
289
  }
283
290
  let data = yield country_1.CountryModel.schema("core", "_").findAll({
@@ -57,5 +57,13 @@ export declare const convertService: ({ convert_type, schema }?: {
57
57
  convert_type?: any[];
58
58
  schema?: {};
59
59
  }) => (req: any, res: any, next: any) => Promise<any>;
60
+ export declare const entryValidateService: ({ module, schema }?: {
61
+ module?: string[];
62
+ schema?: {};
63
+ }) => (req: any, res: any, next: any) => Promise<any>;
64
+ export declare const entryParamService: ({ module, schema }?: {
65
+ module?: string[];
66
+ schema?: {};
67
+ }) => (req: any, res: any, next: any) => Promise<any>;
60
68
  export declare const createdByValidate: (req: any, res: any, next: any) => Promise<any>;
61
69
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
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;
3
+ exports.createdByValidate = exports.entryParamService = exports.entryValidateService = 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");
@@ -291,6 +291,20 @@ const convertService = ({ convert_type = [], schema = {} } = {}) => (req, res, n
291
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
292
  });
293
293
  exports.convertService = convertService;
294
+ 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);
296
+ });
297
+ exports.entryValidateService = entryValidateService;
298
+ const entryParamService = ({ module = ['contact'], schema = {} } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
299
+ if (req.query.module) {
300
+ res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), { module: req.query.module });
301
+ }
302
+ if (req.query.entry_id) {
303
+ res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), { entry_id: req.query.entry_id });
304
+ }
305
+ return (0, exports.paramService)(Joi.object().keys(Object.assign({ module: Joi.string().valid(...module), entry_id: Joi.number().required() }, schema)).unknown())(req, res, next);
306
+ });
307
+ exports.entryParamService = entryParamService;
294
308
  exports.createdByValidate = (0, exports.validateService)(Joi.object().keys({
295
309
  created_by: Joi.alternatives().try(Joi.string(), Joi.number()).required()
296
310
  }).unknown());