vtb-appit 0.0.60 → 0.0.61
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.
- package/appit.js +153 -8
- package/package.json +1 -1
package/appit.js
CHANGED
|
@@ -137,6 +137,7 @@ class Appit {
|
|
|
137
137
|
|
|
138
138
|
async places()
|
|
139
139
|
{
|
|
140
|
+
let placesHistory = {};
|
|
140
141
|
const places = this.transformer.places();
|
|
141
142
|
if(places && places.length) {
|
|
142
143
|
for(let i = 0; i < places.length; i++) {
|
|
@@ -152,14 +153,24 @@ class Appit {
|
|
|
152
153
|
let id = this.findId('places', places[i].object_id);
|
|
153
154
|
if(!id) {
|
|
154
155
|
let model = await this.createPlace({...place, ...images, excursion_id: this.history.excursionId});
|
|
155
|
-
|
|
156
|
+
placesHistory[places[i].object_id] = model.data.id;
|
|
157
|
+
|
|
156
158
|
} else {
|
|
157
159
|
await this.updatePlace(id, {...place, ...images, excursion_id: this.history.excursionId});
|
|
158
160
|
}
|
|
159
161
|
}
|
|
160
162
|
}
|
|
163
|
+
|
|
164
|
+
let nonExisting = this.difference(Object.values(this.history.places), Object.values(placesHistory));
|
|
165
|
+
for(let i = 0; i < nonExisting.length; i++) {
|
|
166
|
+
await this.deletePlace(nonExisting[i]);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
this.history.places = placesHistory;
|
|
161
170
|
}
|
|
162
171
|
|
|
172
|
+
|
|
173
|
+
|
|
163
174
|
async findOrCreateCategory(title)
|
|
164
175
|
{
|
|
165
176
|
let category_id = null;
|
|
@@ -219,6 +230,7 @@ class Appit {
|
|
|
219
230
|
|
|
220
231
|
async organizations()
|
|
221
232
|
{
|
|
233
|
+
let organizationsHistory = {};
|
|
222
234
|
const organizations = this.transformer.organizations();
|
|
223
235
|
if(organizations) {
|
|
224
236
|
for(let i = 0; i < organizations.length; i++) {
|
|
@@ -226,12 +238,19 @@ class Appit {
|
|
|
226
238
|
let id = this.findId('organizations', organizations[i].object_id);
|
|
227
239
|
if(!id) {
|
|
228
240
|
let model = await this.createOrganization(organizations[i]);
|
|
229
|
-
|
|
241
|
+
organizationsHistory[organizations[i].object_id] = model.data.id;
|
|
230
242
|
} else {
|
|
231
243
|
await this.updateOrganization(id, organizations[i]);
|
|
232
244
|
}
|
|
233
245
|
}
|
|
234
246
|
}
|
|
247
|
+
|
|
248
|
+
let nonExisting = this.difference(Object.values(this.history.organizations), Object.values(organizationsHistory));
|
|
249
|
+
for(let i = 0; i < nonExisting.length; i++) {
|
|
250
|
+
await this.deleteOrganization(nonExisting[i]);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
this.history.organizations = organizationsHistory;
|
|
235
254
|
}
|
|
236
255
|
|
|
237
256
|
async notifications()
|
|
@@ -256,6 +275,7 @@ class Appit {
|
|
|
256
275
|
|
|
257
276
|
async members()
|
|
258
277
|
{
|
|
278
|
+
let memberHistory = {};
|
|
259
279
|
const participants = this.transformer.participants();
|
|
260
280
|
if(participants && participants.length) {
|
|
261
281
|
for(let i = 0; i < participants.length; i++) {
|
|
@@ -264,16 +284,24 @@ class Appit {
|
|
|
264
284
|
let id = this.findId('members', participants[i].id);
|
|
265
285
|
if(!id) {
|
|
266
286
|
let model = await this.createMember({...participant, excursion_id: this.history.excursionId});
|
|
267
|
-
|
|
287
|
+
memberHistory[participants[i].id] = model.data.id;
|
|
268
288
|
} else {
|
|
269
289
|
await this.updateMember(id, {...participant, excursion_id: this.history.excursionId});
|
|
270
290
|
}
|
|
271
291
|
}
|
|
272
292
|
}
|
|
293
|
+
|
|
294
|
+
let nonExisting = this.difference(Object.values(this.history.members), Object.values(memberHistory));
|
|
295
|
+
for(let i = 0; i < nonExisting.length; i++) {
|
|
296
|
+
await this.deleteMember(nonExisting[i]);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
this.history.members = memberHistory;
|
|
273
300
|
}
|
|
274
301
|
|
|
275
302
|
async travelInfo()
|
|
276
303
|
{
|
|
304
|
+
let travelInfoHistory = {};
|
|
277
305
|
const travelInfo = this.transformer.travelInfo();
|
|
278
306
|
if(travelInfo && travelInfo.length) {
|
|
279
307
|
for(let i = 0; i < travelInfo.length; i++) {
|
|
@@ -282,16 +310,24 @@ class Appit {
|
|
|
282
310
|
let id = this.findId('travels', travelInfo[i].object_id);
|
|
283
311
|
if(!id) {
|
|
284
312
|
let model = await this.createTravel({...info, excursion_id: this.history.excursionId});
|
|
285
|
-
|
|
313
|
+
travelInfoHistory[travelInfo[i].object_id] = model.data.id;
|
|
286
314
|
} else {
|
|
287
315
|
await this.updateTravel(id, {...info, excursion_id: this.history.excursionId});
|
|
288
316
|
}
|
|
289
317
|
}
|
|
290
318
|
}
|
|
319
|
+
|
|
320
|
+
let nonExisting = this.difference(Object.values(this.history.travels), Object.values(travelInfoHistory));
|
|
321
|
+
for(let i = 0; i < nonExisting.length; i++) {
|
|
322
|
+
await this.deleteTravel(nonExisting[i]);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
this.history.travels = travelInfoHistory;
|
|
291
326
|
}
|
|
292
327
|
|
|
293
328
|
async accommodations()
|
|
294
329
|
{
|
|
330
|
+
let accommodationHistory = {};
|
|
295
331
|
const accommodations = this.transformer.accommodations();
|
|
296
332
|
if(accommodations && accommodations.length) {
|
|
297
333
|
for(let i = 0; i < accommodations.length; i++) {
|
|
@@ -304,16 +340,24 @@ class Appit {
|
|
|
304
340
|
let id = this.findId('accommodations', accommodations[i].object_id);
|
|
305
341
|
if(!id) {
|
|
306
342
|
let model = await this.createAccommodation({...accommodation, ...images, labels: labels, excursion_id: this.history.excursionId});
|
|
307
|
-
|
|
343
|
+
accommodationHistory[accommodations[i].object_id] = model.data.id;
|
|
308
344
|
} else {
|
|
309
345
|
await this.updateAccommodation(id, {...accommodation, ...images, labels: labels, excursion_id: this.history.excursionId});
|
|
310
346
|
}
|
|
311
347
|
}
|
|
312
348
|
}
|
|
349
|
+
|
|
350
|
+
let nonExisting = this.difference(Object.values(this.history.accommodations), Object.values(accommodationHistory));
|
|
351
|
+
for(let i = 0; i < nonExisting.length; i++) {
|
|
352
|
+
await this.deleteAccommodation(nonExisting[i]);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
this.history.accommodations = accommodationHistory;
|
|
313
356
|
}
|
|
314
357
|
|
|
315
358
|
async destinations()
|
|
316
359
|
{
|
|
360
|
+
let destinationHistory = {};
|
|
317
361
|
const destinations = await this.transformer.destinations();
|
|
318
362
|
if(destinations && destinations.length) {
|
|
319
363
|
for(let i = 0; i < destinations.length; i++) {
|
|
@@ -326,16 +370,24 @@ class Appit {
|
|
|
326
370
|
let id = this.findId('destinations', destinations[i].object_id);
|
|
327
371
|
if(!id) {
|
|
328
372
|
let model = await this.createDestination({...destination, ...images, labels: labels, excursion_id: this.history.excursionId});
|
|
329
|
-
|
|
373
|
+
destinationHistory[destinations[i].object_id] = model.data.id;
|
|
330
374
|
} else {
|
|
331
375
|
await this.updateDestination(id, {...destination, ...images, labels: labels, excursion_id: this.history.excursionId});
|
|
332
376
|
}
|
|
333
377
|
}
|
|
334
378
|
}
|
|
379
|
+
|
|
380
|
+
let nonExisting = this.difference(Object.values(this.history.destinations), Object.values(destinationHistory));
|
|
381
|
+
for(let i = 0; i < nonExisting.length; i++) {
|
|
382
|
+
await this.deleteDestination(nonExisting[i]);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
this.history.destinations = destinationHistory;
|
|
335
386
|
}
|
|
336
387
|
|
|
337
388
|
async schemes()
|
|
338
389
|
{
|
|
390
|
+
const schemeHistory = {};
|
|
339
391
|
const schemes = this.transformer.schemes(this.history);
|
|
340
392
|
if(schemes && schemes.length) {
|
|
341
393
|
for(let i = 0; i < schemes.length; i++) {
|
|
@@ -345,16 +397,24 @@ class Appit {
|
|
|
345
397
|
let id = this.findId('schemes', schemes[i].object_id);
|
|
346
398
|
if(!id) {
|
|
347
399
|
let model = await this.createScheme({...scheme, labels: labels, excursion_id: this.history.excursionId});
|
|
348
|
-
|
|
400
|
+
schemeHistory[schemes[i].object_id] = model.data.id;
|
|
349
401
|
} else {
|
|
350
402
|
await this.updateScheme(id, {...scheme, labels: labels, excursion_id: this.history.excursionId});
|
|
351
403
|
}
|
|
352
404
|
}
|
|
353
405
|
}
|
|
406
|
+
|
|
407
|
+
let nonExisting = this.difference(Object.values(this.history.schemes), Object.values(schemeHistory));
|
|
408
|
+
for(let i = 0; i < nonExisting.length; i++) {
|
|
409
|
+
await this.deleteScheme(nonExisting[i]);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
this.history.schemes = schemeHistory;
|
|
354
413
|
}
|
|
355
414
|
|
|
356
415
|
async contacts()
|
|
357
416
|
{
|
|
417
|
+
let contactHistory = {};
|
|
358
418
|
const contacts = this.transformer.contacts();
|
|
359
419
|
if(contacts && contacts.length) {
|
|
360
420
|
for(let i = 0; i < contacts.length; i++) {
|
|
@@ -363,12 +423,19 @@ class Appit {
|
|
|
363
423
|
let id = this.findId('contacts', contacts[i].object_id);
|
|
364
424
|
if(!id) {
|
|
365
425
|
let model = await this.createContact({...contact, excursion_id: this.history.excursionId});
|
|
366
|
-
|
|
426
|
+
contactHistory[contacts[i].object_id] = model.data.id;
|
|
367
427
|
} else {
|
|
368
428
|
await this.updateContact(id, {...contact, excursion_id: this.history.excursionId});
|
|
369
429
|
}
|
|
370
430
|
}
|
|
371
431
|
}
|
|
432
|
+
|
|
433
|
+
let nonExisting = this.difference(Object.values(this.history.contacts), Object.values(contactHistory));
|
|
434
|
+
for(let i = 0; i < nonExisting.length; i++) {
|
|
435
|
+
await this.deleteContact(nonExisting[i]);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
this.history.contacts = contactHistory;
|
|
372
439
|
}
|
|
373
440
|
|
|
374
441
|
getLabels(object)
|
|
@@ -586,6 +653,16 @@ class Appit {
|
|
|
586
653
|
return true;
|
|
587
654
|
}
|
|
588
655
|
|
|
656
|
+
difference(original, current)
|
|
657
|
+
{
|
|
658
|
+
let difference = [];
|
|
659
|
+
original.forEach(id => {
|
|
660
|
+
if(current.indexOf(id) === -1)
|
|
661
|
+
difference.push(id);
|
|
662
|
+
});
|
|
663
|
+
return difference;
|
|
664
|
+
}
|
|
665
|
+
|
|
589
666
|
async createDestination(data)
|
|
590
667
|
{
|
|
591
668
|
return await this.request('POST', `destinations`, data);
|
|
@@ -596,6 +673,11 @@ class Appit {
|
|
|
596
673
|
return await this.request('PUT', `destinations/${id}`, data);
|
|
597
674
|
}
|
|
598
675
|
|
|
676
|
+
async updateDestination(id)
|
|
677
|
+
{
|
|
678
|
+
return await this.request('DELETE', `destinations/${id}`);
|
|
679
|
+
}
|
|
680
|
+
|
|
599
681
|
async createOrganization(data)
|
|
600
682
|
{
|
|
601
683
|
return await this.request('POST', `organizations`, data);
|
|
@@ -606,6 +688,15 @@ class Appit {
|
|
|
606
688
|
return await this.request('PUT', `organizations/${id}`, data);
|
|
607
689
|
}
|
|
608
690
|
|
|
691
|
+
async deleteOrganization(id)
|
|
692
|
+
{
|
|
693
|
+
try {
|
|
694
|
+
return await this.request('DELETE', `organizations/${id}`);
|
|
695
|
+
} catch {
|
|
696
|
+
console.log(`deleteOrganization failed: ${id}`);
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
|
|
609
700
|
async createNotification(data)
|
|
610
701
|
{
|
|
611
702
|
return await this.request('POST', `notifications`, data);
|
|
@@ -626,6 +717,15 @@ class Appit {
|
|
|
626
717
|
return await this.request('PUT', `members/${id}`, data);
|
|
627
718
|
}
|
|
628
719
|
|
|
720
|
+
async deleteMember(id)
|
|
721
|
+
{
|
|
722
|
+
try {
|
|
723
|
+
return await this.request('DELETE', `members/${id}`);
|
|
724
|
+
} catch {
|
|
725
|
+
console.log(`deleteMember failed: ${id}`);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
|
|
629
729
|
async createExcursion(data)
|
|
630
730
|
{
|
|
631
731
|
return await this.request('POST', `excursions`, data);
|
|
@@ -650,6 +750,15 @@ class Appit {
|
|
|
650
750
|
}
|
|
651
751
|
}
|
|
652
752
|
|
|
753
|
+
async deleteTravel(id)
|
|
754
|
+
{
|
|
755
|
+
try {
|
|
756
|
+
return await this.request('DELETE', `travels/${id}`);
|
|
757
|
+
} catch {
|
|
758
|
+
console.log(`deleteTravel failed: ${id}`);
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
|
|
653
762
|
async createScheme(data)
|
|
654
763
|
{
|
|
655
764
|
return await this.request('POST', `schemes`, data);
|
|
@@ -664,6 +773,15 @@ class Appit {
|
|
|
664
773
|
}
|
|
665
774
|
}
|
|
666
775
|
|
|
776
|
+
async deleteScheme(id)
|
|
777
|
+
{
|
|
778
|
+
try {
|
|
779
|
+
return await this.request('DELETE', `schemes/${id}`);
|
|
780
|
+
} catch {
|
|
781
|
+
console.log(`deleteScheme failed: ${id}`);
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
|
|
667
785
|
async createContact(data)
|
|
668
786
|
{
|
|
669
787
|
return await this.request('POST', `contacts`, data);
|
|
@@ -678,6 +796,15 @@ class Appit {
|
|
|
678
796
|
}
|
|
679
797
|
}
|
|
680
798
|
|
|
799
|
+
async deleteContact(id)
|
|
800
|
+
{
|
|
801
|
+
try {
|
|
802
|
+
return await this.request('DELETE', `contacts/${id}`);
|
|
803
|
+
} catch {
|
|
804
|
+
console.log(`deleteContact failed: ${id}`);
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
|
|
681
808
|
async createAccommodation(data)
|
|
682
809
|
{
|
|
683
810
|
return await this.request('POST', `accommodations`, data);
|
|
@@ -692,6 +819,15 @@ class Appit {
|
|
|
692
819
|
}
|
|
693
820
|
}
|
|
694
821
|
|
|
822
|
+
async deleteAccommodation(id)
|
|
823
|
+
{
|
|
824
|
+
try {
|
|
825
|
+
return await this.request('DELETE', `accommodations/${id}`);
|
|
826
|
+
} catch {
|
|
827
|
+
console.log(`deleteAccommodation failed: ${id}`);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
|
|
695
831
|
async createPlace(data)
|
|
696
832
|
{
|
|
697
833
|
return await this.request('POST', `places`, data);
|
|
@@ -706,6 +842,15 @@ class Appit {
|
|
|
706
842
|
}
|
|
707
843
|
}
|
|
708
844
|
|
|
845
|
+
async deletePlace(id)
|
|
846
|
+
{
|
|
847
|
+
try {
|
|
848
|
+
return await this.request('DELETE', `places/${id}`);
|
|
849
|
+
} catch {
|
|
850
|
+
console.log(`deletePlace failed: ${id}`);
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
|
|
709
854
|
async createFlight(data)
|
|
710
855
|
{
|
|
711
856
|
return await this.request('POST', `flights`, data);
|