vtb-appit 0.0.89 → 0.0.91

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.
Files changed (2) hide show
  1. package/appit.js +57 -0
  2. package/package.json +1 -1
package/appit.js CHANGED
@@ -30,6 +30,7 @@ class Appit {
30
30
  this.history = {
31
31
  excursionId: null,
32
32
  members: {},
33
+ ships: {},
33
34
  contacts: {},
34
35
  organizations: {},
35
36
  travels: {},
@@ -76,6 +77,7 @@ class Appit {
76
77
 
77
78
  await this.excursion();
78
79
  await this.labels();
80
+ await this.ships();
79
81
  await this.places();
80
82
  await this.organizations();
81
83
  await this.members();
@@ -208,6 +210,37 @@ class Appit {
208
210
  return category_id;
209
211
  }
210
212
 
213
+ async ships()
214
+ {
215
+ const ships = this.transformer.ships();
216
+ let shipsHistory = {};
217
+ if(ships && ships.length) {
218
+ for(let i = 0; i < ships.length; i++) {
219
+ let ship = this.clean(JSON.parse(JSON.stringify(ships[i])));
220
+
221
+ const images = (ship.images.length) ? await this.getImages(ship.images, 'original/lg') : {};
222
+ delete ship.images;
223
+
224
+ let id = this.findId('ships', ships[i].object_id);
225
+ if(!id) {
226
+ let model = await this.createShip({...ship, ...images, excursion_id: this.history.excursionId});
227
+ shipsHistory[ships[i].object_id] = model.data.id;
228
+ } else {
229
+ let model = await this.updateFlight(id, {...ship, ...images, excursion_id: this.history.excursionId});
230
+ shipsHistory[ships[i].object_id] = model.data.id;
231
+ }
232
+ }
233
+ }
234
+
235
+ let nonExisting = this.difference(Object.values(this.history.ships), Object.values(shipsHistory));
236
+ for(let i = 0; i < nonExisting.length; i++) {
237
+ await this.deleteShips(nonExisting[i]);
238
+ }
239
+
240
+ this.history.ships = shipsHistory;
241
+ }
242
+
243
+
211
244
  async flights()
212
245
  {
213
246
  const flights = this.transformer.flights();
@@ -1045,6 +1078,30 @@ class Appit {
1045
1078
  }
1046
1079
  }
1047
1080
 
1081
+ async createShip(data)
1082
+ {
1083
+ return await this.request('POST', `ships`, data);
1084
+ }
1085
+
1086
+ async updateShip(id, data)
1087
+ {
1088
+ try {
1089
+ return await this.request('PUT', `ships/${id}`, data);
1090
+ } catch {
1091
+ console.log(`updateShip failed: ${id}`);
1092
+ }
1093
+ }
1094
+
1095
+ async deleteShip(id)
1096
+ {
1097
+ try {
1098
+ return await this.request('DELETE', `ships/${id}`);
1099
+ } catch {
1100
+ console.log(`deleteShip failed: ${id}`);
1101
+ }
1102
+ }
1103
+
1104
+
1048
1105
  async createFlightImage(data)
1049
1106
  {
1050
1107
  return await this.request('POST', `flights/save-pictures`, data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vtb-appit",
3
- "version": "0.0.89",
3
+ "version": "0.0.91",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {},