@digione/node-custom-api 0.1.9-beta2 → 0.1.9-beta4

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.9-beta2",
3
+ "version": "0.1.9-beta4",
4
4
  "description": "Typescript node digione-api",
5
5
  "author": "Monchai Jirayupong <monchai.j@seven.co.th>",
6
6
  "license": "MIT",
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'];
@@ -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,6 +472,7 @@ class StreamUtil {
472
472
  continue;
473
473
  }
474
474
  if (convert_option) {
475
+ let obj_value = {};
475
476
  if (item['field_type'] == "choice") {
476
477
  if (field_data['choice_data']) {
477
478
  let data = [];
@@ -501,6 +502,9 @@ class StreamUtil {
501
502
  else {
502
503
  data[k] = { key: v, value: v };
503
504
  }
505
+ if (convert_value && data[k]) {
506
+ obj_value[data[k]['key']] = data[k]['value'];
507
+ }
504
508
  });
505
509
  item['data'] = data;
506
510
  }
@@ -510,9 +514,18 @@ class StreamUtil {
510
514
  if (value && value.indexOf('lang:') > -1) {
511
515
  item['value'] = (0, i18n_1.__)({ phrase: value, locale: lang_code });
512
516
  }
517
+ if (convert_value && item['key']) {
518
+ obj_value[item['key']] = item['value'];
519
+ }
513
520
  return item;
514
521
  });
515
522
  }
523
+ if (convert_value && typeof item['field_value'] != "undefined") {
524
+ let field_value = item['field_value'];
525
+ if (item['field_value'] == null)
526
+ field_value = '';
527
+ field_data['value'] = obj_value[field_value];
528
+ }
516
529
  }
517
530
  else if (!field_option[item['field_slug']] && (item['field_type'] == "relationship" || item['field_type'] == "multiple") && field_data['choose_stream']) {
518
531
  try {
@@ -557,6 +570,9 @@ class StreamUtil {
557
570
  item['title'] = item['title'] ? item['title'] : item[stream['title_column']];
558
571
  (0, helper_2.getValueFunctionLang)('title')(item, { result: item, lang_code });
559
572
  let value = item['title'] ? item['title'] : item['id'];
573
+ if (convert_value && item['id']) {
574
+ obj_value[item['id']] = value;
575
+ }
560
576
  return {
561
577
  key: item['id'],
562
578
  value
@@ -567,6 +583,9 @@ class StreamUtil {
567
583
  }
568
584
  }
569
585
  item['data'] = data;
586
+ if (convert_value && item['field_value']) {
587
+ field_data['value'] = obj_value[item['field_value']];
588
+ }
570
589
  }
571
590
  catch (err) { }
572
591
  }
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({