@digione/node-custom-api 0.1.1 → 0.1.3

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.1",
3
+ "version": "0.1.3",
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
@@ -267,7 +267,7 @@ class StreamUtil {
267
267
  }
268
268
  if (attributes)
269
269
  build['attributes'] = attributes;
270
- if (builder)
270
+ if (builder && query)
271
271
  this.builder[slug + "_" + namespace] = build;
272
272
  return build;
273
273
  });
package/utils/user.d.ts CHANGED
@@ -39,6 +39,10 @@ export declare const getUserInOrgan: (ref: string, { where, organ_id, attributes
39
39
  export declare const convertAddress: (data: any, { lang_code }?: {
40
40
  lang_code?: string;
41
41
  }) => Promise<any>;
42
+ export declare const getAddressIndex: (data: any, { condition, lang_code }?: {
43
+ condition?: {};
44
+ lang_code?: string;
45
+ }) => Promise<{}>;
42
46
  export declare const getCountry: (ref: string, { organ_id, lang_code, setting }?: {
43
47
  organ_id?: string;
44
48
  lang_code?: string;
package/utils/user.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getB2bSetting = exports.getGroupPermission = exports.getGroupSetting = exports.getCountry = exports.convertAddress = exports.getUserInOrgan = exports.createUser = exports.upsertProfile = exports.createOrgan = exports.getOrganMemberId = exports.getUser = void 0;
3
+ exports.getB2bSetting = exports.getGroupPermission = exports.getGroupSetting = exports.getCountry = exports.getAddressIndex = exports.convertAddress = exports.getUserInOrgan = exports.createUser = exports.upsertProfile = exports.createOrgan = exports.getOrganMemberId = exports.getUser = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const user_1 = require("../models/user/user");
6
6
  const organ_1 = require("../models/user/organ");
@@ -211,6 +211,52 @@ const convertAddress = (data, { lang_code = "en" } = {}) => tslib_1.__awaiter(vo
211
211
  return data;
212
212
  });
213
213
  exports.convertAddress = convertAddress;
214
+ const getAddressIndex = (data, { condition = {}, lang_code = "en" } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
215
+ let result = {}, where = { lang_code: [lang_code, "en"] }, bol = false;
216
+ let order = [sequelize.literal(`FIELD(lang_code,${'\'' + where['lang_code'].join('\',\'') + '\''})`)];
217
+ if (!bol && data['country'] && !condition['country_id']) {
218
+ let country = yield country_1.CountryModel.schema("core", "_").findOne({
219
+ raw: true, where: Object.assign(Object.assign({}, where), { country_name: data['country'] }), attributes: ['id'], order
220
+ });
221
+ if (country) {
222
+ result['country_id'] = country['id'];
223
+ condition['country_id'] = result['country_id'];
224
+ }
225
+ bol = (typeof result['country_id'] == "undefined");
226
+ }
227
+ if (!bol && data['state'] && !condition['state_id']) {
228
+ let country_id = condition['country_id'] || null;
229
+ let state = yield state_1.StateModel.schema("core", "_").findOne({
230
+ raw: true, where: Object.assign(Object.assign({}, where), { country_id, state_name: data['state'] }), attributes: ['id'], order
231
+ });
232
+ if (state) {
233
+ result['state_id'] = state['id'];
234
+ condition['country_id'] = result['state_id'];
235
+ }
236
+ bol = (typeof result['state_id'] == "undefined");
237
+ }
238
+ if (!bol && data['city'] && !condition['city_id']) {
239
+ let state_id = condition['state_id'] || null;
240
+ let city = yield city_1.CityModel.schema("core", "_").findOne({
241
+ raw: true, where: Object.assign(Object.assign({}, where), { state_id, city_name: data['city'] }), attributes: ['id'], order
242
+ });
243
+ if (city) {
244
+ result['city_id'] = city['id'];
245
+ condition['city_id'] = result['city_id'];
246
+ }
247
+ bol = (typeof result['city_id'] == "undefined");
248
+ }
249
+ if (!bol && data['district']) {
250
+ let city_id = condition['city_id'] || null;
251
+ let district = yield district_1.DistrictModel.schema("core", "_").findOne({
252
+ raw: true, where: Object.assign(Object.assign({}, where), { city_id, district_name: data['district'] }), attributes: ['id'], order
253
+ });
254
+ if (district)
255
+ result['district_id'] = district['id'];
256
+ }
257
+ return result;
258
+ });
259
+ exports.getAddressIndex = getAddressIndex;
214
260
  const getCountry = (ref, { organ_id = "", lang_code = "en", setting = {} } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
215
261
  let where = { status: 1, lang_code }, default_country;
216
262
  if (setting['country_id']) {