@digione/node-custom-api 0.1.7-beta1 → 0.1.8-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.
- package/package.json +1 -1
- package/utils/user.d.ts +2 -1
- package/utils/user.js +36 -18
package/package.json
CHANGED
package/utils/user.d.ts
CHANGED
|
@@ -36,8 +36,9 @@ export declare const getUserInOrgan: (ref: string, { where, organ_id, attributes
|
|
|
36
36
|
attributes?: string[];
|
|
37
37
|
parent?: boolean;
|
|
38
38
|
}) => Promise<sequelize.Model<any, any>>;
|
|
39
|
-
export declare const convertAddress: (data: any, { lang_code }?: {
|
|
39
|
+
export declare const convertAddress: (data: any, { lang_code, transform }?: {
|
|
40
40
|
lang_code?: string;
|
|
41
|
+
transform?: boolean;
|
|
41
42
|
}) => Promise<any>;
|
|
42
43
|
export declare const getAddressIndex: (data: any, { condition, lang_code }?: {
|
|
43
44
|
condition?: {};
|
package/utils/user.js
CHANGED
|
@@ -177,36 +177,54 @@ const getUserInOrgan = (ref, { where = {}, organ_id = "", attributes = ['id', 'o
|
|
|
177
177
|
});
|
|
178
178
|
});
|
|
179
179
|
exports.getUserInOrgan = getUserInOrgan;
|
|
180
|
-
const convertAddress = (data, { lang_code = "en" } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
181
|
-
let where = { lang_code: [lang_code, "en"], status: '1' };
|
|
180
|
+
const convertAddress = (data, { lang_code = "en", transform = false } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
181
|
+
let where = { lang_code: [lang_code, "en"], status: '1' }, limit = 1, attributes = [];
|
|
182
182
|
let order = [sequelize.literal(`FIELD(lang_code,${'\'' + where['lang_code'].join('\',\'') + '\''})`)];
|
|
183
|
+
if (transform) {
|
|
184
|
+
where = { status: '1' };
|
|
185
|
+
attributes = ['lang_code'];
|
|
186
|
+
limit = undefined;
|
|
187
|
+
order = undefined;
|
|
188
|
+
}
|
|
183
189
|
if (data['country_id']) {
|
|
184
|
-
let country = yield country_1.CountryModel.schema("core", "_").
|
|
185
|
-
raw: true, where: Object.assign(Object.assign({}, where), { id: data['country_id'] }), attributes: ['country_name'], order
|
|
190
|
+
let country = yield country_1.CountryModel.schema("core", "_").findAll({
|
|
191
|
+
raw: true, where: Object.assign(Object.assign({}, where), { id: data['country_id'] }), attributes: ['country_name', ...attributes], order, limit
|
|
186
192
|
});
|
|
187
|
-
if (country)
|
|
188
|
-
data['country'] = country['country_name'];
|
|
193
|
+
if (country.length) {
|
|
194
|
+
data['country'] = country[0]['country_name'];
|
|
195
|
+
if (transform)
|
|
196
|
+
data['country'] = JSON.stringify(country.reduce((total, item) => Object.assign(total, { [item['lang_code']]: item['country_name'] }), {}));
|
|
197
|
+
}
|
|
189
198
|
}
|
|
190
199
|
if (data['state_id']) {
|
|
191
|
-
let state = yield state_1.StateModel.schema("core", "_").
|
|
192
|
-
raw: true, where: Object.assign(Object.assign({}, where), { id: data['state_id'] }), attributes: ['state_name'], order
|
|
200
|
+
let state = yield state_1.StateModel.schema("core", "_").findAll({
|
|
201
|
+
raw: true, where: Object.assign(Object.assign({}, where), { id: data['state_id'] }), attributes: ['state_name', ...attributes], order, limit
|
|
193
202
|
});
|
|
194
|
-
if (state)
|
|
195
|
-
data['state'] = state['state_name'];
|
|
203
|
+
if (state.length) {
|
|
204
|
+
data['state'] = state[0]['state_name'];
|
|
205
|
+
if (transform)
|
|
206
|
+
data['state'] = JSON.stringify(state.reduce((total, item) => Object.assign(total, { [item['lang_code']]: item['state_name'] }), {}));
|
|
207
|
+
}
|
|
196
208
|
}
|
|
197
209
|
if (data['city_id']) {
|
|
198
|
-
let city = yield city_1.CityModel.schema("core", "_").
|
|
199
|
-
raw: true, where: Object.assign(Object.assign({}, where), { id: data['city_id'] }), attributes: ['city_name'], order
|
|
210
|
+
let city = yield city_1.CityModel.schema("core", "_").findAll({
|
|
211
|
+
raw: true, where: Object.assign(Object.assign({}, where), { id: data['city_id'] }), attributes: ['city_name', ...attributes], order, limit
|
|
200
212
|
});
|
|
201
|
-
if (city)
|
|
202
|
-
data['city'] = city['city_name'];
|
|
213
|
+
if (city.length) {
|
|
214
|
+
data['city'] = city[0]['city_name'];
|
|
215
|
+
if (transform)
|
|
216
|
+
data['city'] = JSON.stringify(city.reduce((total, item) => Object.assign(total, { [item['lang_code']]: item['city_name'] }), {}));
|
|
217
|
+
}
|
|
203
218
|
}
|
|
204
219
|
if (data['district_id']) {
|
|
205
|
-
let district = yield district_1.DistrictModel.schema("core", "_").
|
|
206
|
-
raw: true, where: Object.assign(Object.assign({}, where), { id: data['district_id'] }), attributes: ['district_name'], order
|
|
220
|
+
let district = yield district_1.DistrictModel.schema("core", "_").findAll({
|
|
221
|
+
raw: true, where: Object.assign(Object.assign({}, where), { id: data['district_id'] }), attributes: ['district_name', ...attributes], order, limit
|
|
207
222
|
});
|
|
208
|
-
if (district)
|
|
209
|
-
data['district'] = district['district_name'];
|
|
223
|
+
if (district.length) {
|
|
224
|
+
data['district'] = district[0]['district_name'];
|
|
225
|
+
if (transform)
|
|
226
|
+
data['district'] = JSON.stringify(district.reduce((total, item) => Object.assign(total, { [item['lang_code']]: item['district_name'] }), {}));
|
|
227
|
+
}
|
|
210
228
|
}
|
|
211
229
|
return data;
|
|
212
230
|
});
|