vtb-appit 0.0.88 → 0.0.90

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.
@@ -199,6 +199,8 @@ class AppitBaseTransformer {
199
199
  id: document.id,
200
200
  filename: document.filename,
201
201
  original_filename: document.original_filename,
202
+ description: document.description,
203
+ isShared: document.isShared,
202
204
  data: buffer
203
205
  });
204
206
  });
@@ -347,4 +349,4 @@ class AppitBaseTransformer {
347
349
  }
348
350
  }
349
351
 
350
- module.exports = { AppitBaseTransformer };
352
+ module.exports = { AppitBaseTransformer };
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();
@@ -969,11 +1002,19 @@ class Appit {
969
1002
  formData.append('content', data.content);
970
1003
 
971
1004
  if(data.files) {
972
- data.files.forEach(file => {
973
- formData.append('files[id][]', '');
974
- formData.append('files[title][]', data.title);
975
- formData.append('files[file][]', fs.createReadStream(file));
976
- })
1005
+ if(data.files.file) {
1006
+ data.files.file.forEach((file, key) => {
1007
+ formData.append('files[id][]', '');
1008
+ formData.append('files[title][]', data.files.title[key]);
1009
+ formData.append('files[file][]', fs.createReadStream(file));
1010
+ })
1011
+ } else {
1012
+ data.files.forEach(file => {
1013
+ formData.append('files[id][]', '');
1014
+ formData.append('files[title][]', data.title);
1015
+ formData.append('files[file][]', fs.createReadStream(file));
1016
+ })
1017
+ }
977
1018
  } else if(data.file) {
978
1019
  formData.append('files[id][]', '');
979
1020
  formData.append('files[title][]', data.title);
@@ -1037,6 +1078,30 @@ class Appit {
1037
1078
  }
1038
1079
  }
1039
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
+
1040
1105
  async createFlightImage(data)
1041
1106
  {
1042
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.88",
3
+ "version": "0.0.90",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {},