vtb-appit 0.1.1 → 0.1.3

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 +31 -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()
@@ -1028,12 +1036,24 @@ class Appit {
1028
1036
  if(data.files) {
1029
1037
  if(data.files.file) {
1030
1038
  data.files.file.forEach((file, key) => {
1039
+ const stats = fs.statSync(file);
1040
+ const fileSizeInMB = stats.size / (1024 * 1024);
1041
+ if(fileSizeInMB > 20) {
1042
+ console.log("FILE SIZE TOO BIG");
1043
+ return false;
1044
+ }
1031
1045
  formData.append('files[id][]', '');
1032
1046
  formData.append('files[title][]', data.files.title[key]);
1033
1047
  formData.append('files[file][]', fs.createReadStream(file));
1034
1048
  })
1035
1049
  } else {
1036
1050
  data.files.forEach(file => {
1051
+ const stats = fs.statSync(file);
1052
+ const fileSizeInMB = stats.size / (1024 * 1024);
1053
+ if(fileSizeInMB > 20) {
1054
+ console.log("FILE SIZE TOO BIG");
1055
+ return false;
1056
+ }
1037
1057
  formData.append('files[id][]', '');
1038
1058
  formData.append('files[title][]', data.title);
1039
1059
  formData.append('files[file][]', fs.createReadStream(file));
@@ -1070,6 +1090,15 @@ class Appit {
1070
1090
  }
1071
1091
  }
1072
1092
 
1093
+ async deleteDocuments(id, data)
1094
+ {
1095
+ try {
1096
+ return await this.request('DELETE', `documents/${id}`, data);
1097
+ } catch {
1098
+ console.log(`deleteDocument failed: ${id}`);
1099
+ }
1100
+ }
1101
+
1073
1102
  async deletePlace(id)
1074
1103
  {
1075
1104
  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.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {},