vtb-appit 0.0.40 → 0.0.43

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.
@@ -37,6 +37,11 @@ class AppitBaseTransformer {
37
37
  return false;
38
38
  }
39
39
 
40
+ flights()
41
+ {
42
+ return false;
43
+ }
44
+
40
45
  places()
41
46
  {
42
47
  return false;
package/appit.js CHANGED
@@ -34,7 +34,8 @@ class Appit {
34
34
  accommodations: {},
35
35
  schemes: {},
36
36
  labels: {},
37
- destinations: {}
37
+ destinations: {},
38
+ flights: {}
38
39
  };
39
40
 
40
41
  try {
@@ -66,6 +67,7 @@ class Appit {
66
67
  await this.accommodations();
67
68
  await this.schemes();
68
69
  await this.destinations();
70
+ await this.flights();
69
71
 
70
72
  this.history.updatedAt = new Date().getTime();
71
73
 
@@ -111,12 +113,33 @@ class Appit {
111
113
  for(let i = 0; i < places.length; i++) {
112
114
  let place = this.clean(JSON.parse(JSON.stringify(places[i])));
113
115
 
116
+ const images = (place.images.length) ? await this.getImages(place.images, 'original/lg') : {};
117
+ delete place.images;
118
+
114
119
  let id = this.findId('places', places[i].object_id);
115
120
  if(!id) {
116
- let model = await this.createPlace({...place, excursion_id: this.history.excursionId});
121
+ let model = await this.createPlace({...place, ...images, excursion_id: this.history.excursionId});
117
122
  this.history.places[places[i].object_id] = model.data.id;
118
123
  } else {
119
- await this.updatePlace(id, {...place, excursion_id: this.history.excursionId});
124
+ await this.updatePlace(id, {...place, ...images, excursion_id: this.history.excursionId});
125
+ }
126
+ }
127
+ }
128
+ }
129
+
130
+ async flights()
131
+ {
132
+ const flights = this.transformer.flights();
133
+ if(flights && flights.length) {
134
+ for(let i = 0; i < flights.length; i++) {
135
+ let flight = this.clean(JSON.parse(JSON.stringify(flights[i])));
136
+
137
+ let id = this.findId('flights', flights[i].object_id);
138
+ if(!id) {
139
+ let model = await this.createFlight({...flight, excursion_id: this.history.excursionId});
140
+ this.history.flights[flights[i].object_id] = model.data.id;
141
+ } else {
142
+ await this.updateFlight(id, {...flight, excursion_id: this.history.excursionId});
120
143
  }
121
144
  }
122
145
  }
@@ -183,16 +206,15 @@ class Appit {
183
206
  let accommodation = this.clean(JSON.parse(JSON.stringify(accommodations[i])));
184
207
  let labels = this.getLabels(accommodations[i]);
185
208
 
186
- if(accommodation.images && accommodation.images.length) {
187
- accommodation.images = await this.mediaToBase64(accommodation.images);
188
- }
209
+ const images = (accommodation.images.length) ? await this.getImages(accommodation.images, 'original/lg') : {};
210
+ delete accommodation.images;
189
211
 
190
212
  let id = this.findId('accommodations', accommodations[i].object_id);
191
213
  if(!id) {
192
- let model = await this.createAccommodation({...accommodation, labels: labels, excursion_id: this.history.excursionId});
214
+ let model = await this.createAccommodation({...accommodation, ...images, labels: labels, excursion_id: this.history.excursionId});
193
215
  this.history.accommodations[accommodations[i].object_id] = model.data.id;
194
216
  } else {
195
- await this.updateAccommodation(id, {...accommodation, labels: labels, excursion_id: this.history.excursionId});
217
+ await this.updateAccommodation(id, {...accommodation, ...images, labels: labels, excursion_id: this.history.excursionId});
196
218
  }
197
219
  }
198
220
  }
@@ -248,9 +270,9 @@ class Appit {
248
270
  return [];
249
271
  }
250
272
 
251
- getImages(media, crop)
273
+ async getImages(media, crop)
252
274
  {
253
- const result = {
275
+ let result = {
254
276
  file_size: [],
255
277
  file_mime_type: [],
256
278
  file_name: [],
@@ -259,8 +281,26 @@ class Appit {
259
281
  file_type: []
260
282
  };
261
283
 
262
- return new Promise((resolve, reject) => {
263
- media.forEach(image => {
284
+ const parsed = await this.getImageParsed(media, crop);
285
+
286
+ parsed.forEach(image => {
287
+ result.file_name.push(image.file_name);
288
+ result.file_path.push(image.file_path);
289
+ result.file_mime_type.push(image.file_mime_type);
290
+ result.file_size.push(image.file_size);
291
+ result.file_active.push(image.file_active);
292
+ result.file_type.push(image.file_type);
293
+ });
294
+
295
+ return result;
296
+ }
297
+
298
+ getImageParsed(media, crop)
299
+ {
300
+ let promises = []
301
+
302
+ media.forEach(image => {
303
+ promises.push(new Promise((resolve, reject) => {
264
304
  const regex = (image.url.match(/amazonaws\.com/)) ? /\.com\/(.*?)\/((?:.*?)\/(?:.*?))\//g : /\.(?:nl|com|travel|io|be)\.?\/((?:.*?)\/(?:.*?))\//g;
265
305
  const match = regex.exec(image.url);
266
306
 
@@ -274,22 +314,26 @@ class Appit {
274
314
  res.on('data', chunk => {
275
315
  body += chunk;
276
316
  })
277
-
317
+
278
318
  res.on('end', () => {
279
319
  const frags = image.url.split('/');
280
- result.file_name.push(frags[frags.length - 1]);
281
- result.file_path.push(image.url);
282
- result.file_mime_type.push(res.headers['content-type']);
283
- result.file_size.push(res.headers['content-length']);
284
- result.file_active.push(1)
285
- result.file_type.push(1);
286
-
287
- resolve(result);
320
+
321
+ resolve({
322
+ file_name: frags[frags.length - 1],
323
+ file_path: image.url,
324
+ file_mime_type: res.headers['content-type'],
325
+ file_size: res.headers['content-length'],
326
+ file_active: 1,
327
+ file_type: 1
328
+ });
288
329
  })
289
330
  });
290
331
  req.end();
291
- });
292
- })
332
+ }));
333
+ });
334
+
335
+
336
+ return Promise.all(promises);
293
337
  }
294
338
 
295
339
  async mediaToBase64(media)
@@ -517,6 +561,20 @@ class Appit {
517
561
  }
518
562
  }
519
563
 
564
+ async createFlight(data)
565
+ {
566
+ return await this.request('POST', `flights`, data);
567
+ }
568
+
569
+ async updateFlight(id, data)
570
+ {
571
+ try {
572
+ return await this.request('PUT', `flights/${id}`, data);
573
+ } catch {
574
+ console.log(`updateFlight failed: ${id}`);
575
+ }
576
+ }
577
+
520
578
  async createLabel(workspace_id, data)
521
579
  {
522
580
  return await this.request('POST', `workspaces/${workspace_id}/labels`, data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vtb-appit",
3
- "version": "0.0.40",
3
+ "version": "0.0.43",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {