vtb-appit 0.0.49 → 0.0.51
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/appit.js +29 -1
- package/package.json +1 -1
package/appit.js
CHANGED
|
@@ -130,6 +130,10 @@ class Appit {
|
|
|
130
130
|
const images = (place.images.length) ? await this.getImages(place.images, 'original/lg') : {};
|
|
131
131
|
delete place.images;
|
|
132
132
|
|
|
133
|
+
if(place.category_id && typeof place.category_id === 'string') {
|
|
134
|
+
place.category_id = await this.findOrCreateCategory(place.category_id);
|
|
135
|
+
}
|
|
136
|
+
|
|
133
137
|
let id = this.findId('places', places[i].object_id);
|
|
134
138
|
if(!id) {
|
|
135
139
|
let model = await this.createPlace({...place, ...images, excursion_id: this.history.excursionId});
|
|
@@ -141,6 +145,28 @@ class Appit {
|
|
|
141
145
|
}
|
|
142
146
|
}
|
|
143
147
|
|
|
148
|
+
async findOrCreateCategory(title)
|
|
149
|
+
{
|
|
150
|
+
let category_id = null;
|
|
151
|
+
let categories = await this.request('GET', `categories?per_page=50000`);
|
|
152
|
+
if(categories && categories.success) {
|
|
153
|
+
categories.data.data.forEach(category => {
|
|
154
|
+
if(category.title === title) {
|
|
155
|
+
category_id = category.id;
|
|
156
|
+
}
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
if(!category_id) {
|
|
160
|
+
let result = await this.request('POST', `categories`, {title: title});
|
|
161
|
+
if(result && result.success) {
|
|
162
|
+
category_id = result.data.id;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return category_id;
|
|
168
|
+
}
|
|
169
|
+
|
|
144
170
|
async flights()
|
|
145
171
|
{
|
|
146
172
|
const flights = this.transformer.flights();
|
|
@@ -410,11 +436,13 @@ class Appit {
|
|
|
410
436
|
hostname: this.hostname,
|
|
411
437
|
path: pth.join(this.pathPrefix, path),
|
|
412
438
|
method: method,
|
|
439
|
+
headers: {}
|
|
413
440
|
}
|
|
414
441
|
|
|
415
442
|
if(payload) {
|
|
416
443
|
options.headers = {
|
|
417
|
-
'Content-Type': 'application/json'
|
|
444
|
+
'Content-Type': 'application/json',
|
|
445
|
+
'Content-Language': 'nl'
|
|
418
446
|
};
|
|
419
447
|
}
|
|
420
448
|
|