vtb-appit 0.1.1 → 0.1.2

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 +19 -2
  2. package/package.json +1 -1
package/appit.js CHANGED
@@ -418,6 +418,7 @@ class Appit {
418
418
  async documents()
419
419
  {
420
420
  const documents = this.transformer.documents();
421
+ let documentHistory = {};
421
422
  if(documents) {
422
423
  for(let i = 0; i < documents.length; i++) {
423
424
  documents[i].excursion_id = this.history.excursionId;
@@ -426,12 +427,19 @@ class Appit {
426
427
  let model = await this.createDocument(documents[i]);
427
428
  console.log('documents', model);
428
429
  if(typeof model === 'object' && model.data && model.data.id)
429
- this.history.documents[documents[i].object_id] = model.data.id;
430
+ documentHistory[documents[i].object_id] = model.data.id;
430
431
  } else {
431
- await this.updateDocument(id, documents[i]);
432
+ documentHistory[documents[i].object_id] = id;
432
433
  }
433
434
  }
434
435
  }
436
+
437
+ let nonExisting = this.difference(Object.values(this.history.documents), Object.values(documentHistory));
438
+ for(let i = 0; i < nonExisting.length; i++) {
439
+ await this.deleteDocuments(nonExisting[i]);
440
+ }
441
+
442
+ this.history.documents = documentHistory;
435
443
  }
436
444
 
437
445
  async accommodations()
@@ -1070,6 +1078,15 @@ class Appit {
1070
1078
  }
1071
1079
  }
1072
1080
 
1081
+ async deleteDocuments(id, data)
1082
+ {
1083
+ try {
1084
+ return await this.request('DELETE', `documents/${id}`, data);
1085
+ } catch {
1086
+ console.log(`deleteDocument failed: ${id}`);
1087
+ }
1088
+ }
1089
+
1073
1090
  async deletePlace(id)
1074
1091
  {
1075
1092
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vtb-appit",
3
- "version": "0.1.01",
3
+ "version": "0.1.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {},