ti2-ventrata 1.0.35 → 1.0.37
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/index.js +39 -37
- package/package.json +1 -1
- package/resolvers/availability.js +6 -2
package/index.js
CHANGED
|
@@ -359,6 +359,34 @@ class Plugin {
|
|
|
359
359
|
acceptLanguage,
|
|
360
360
|
});
|
|
361
361
|
const dataForCreateBooking = await jwt.verify(availabilityKey, this.jwtKey);
|
|
362
|
+
// if customFieldValues contains perUnitItem fields
|
|
363
|
+
// we need to overwrite unitItems from the availabilityKey
|
|
364
|
+
if (customFieldValues && customFieldValues.length) {
|
|
365
|
+
const productCFV = customFieldValues.filter(o => !R.isNil(o.value) && !o.field.isPerUnitItem);
|
|
366
|
+
const unitItemCFV = customFieldValues.filter(o => !R.isNil(o.value) && o.field.isPerUnitItem);
|
|
367
|
+
if (productCFV.length) {
|
|
368
|
+
dataForCreateBooking.questionAnswers = productCFV.map(o => ({
|
|
369
|
+
questionId: o.field.id,
|
|
370
|
+
value: o.value,
|
|
371
|
+
}));
|
|
372
|
+
}
|
|
373
|
+
if (unitItemCFV.length) {
|
|
374
|
+
dataForCreateBooking.unitItems = R.call(R.compose(
|
|
375
|
+
R.map(arr => ({
|
|
376
|
+
unitId: arr[0].field.unitId,
|
|
377
|
+
questionAnswers: arr.map(o => ({
|
|
378
|
+
questionId: o.field.id.split('|')[0],
|
|
379
|
+
value: o.value,
|
|
380
|
+
})),
|
|
381
|
+
})),
|
|
382
|
+
R.values,
|
|
383
|
+
R.groupBy(o => {
|
|
384
|
+
const [questionId, unitItemIndex] = o.field.id.split('|');
|
|
385
|
+
return unitItemIndex;
|
|
386
|
+
}),
|
|
387
|
+
), unitItemCFV);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
362
390
|
let booking = R.path(['data'], await axios({
|
|
363
391
|
method: rebookingId ? 'patch' : 'post',
|
|
364
392
|
url: `${endpoint || this.endpoint}/bookings${rebookingId ? `/${rebookingId}` : ''}`,
|
|
@@ -371,36 +399,6 @@ class Plugin {
|
|
|
371
399
|
},
|
|
372
400
|
headers,
|
|
373
401
|
}));
|
|
374
|
-
const answers = customFieldValues && customFieldValues.length
|
|
375
|
-
? customFieldValues.filter(o => !R.isNil(o.value)).map(o => ({
|
|
376
|
-
questionId: o.field.id,
|
|
377
|
-
value: o.value,
|
|
378
|
-
})) : [];
|
|
379
|
-
// for answers to custom fields, ventrata suggest to modify the booking
|
|
380
|
-
if (answers.length) {
|
|
381
|
-
let modifierBooking = {
|
|
382
|
-
questionAnswers: booking.questionAnswers.map(o => {
|
|
383
|
-
const answer = answers.find(a => a.questionId === o.questionId);
|
|
384
|
-
return answer || o;
|
|
385
|
-
}),
|
|
386
|
-
unitItems: booking.unitItems.map(u => ({
|
|
387
|
-
...u,
|
|
388
|
-
questionAnswers: u.questionAnswers.map(o => {
|
|
389
|
-
const answer = answers.find(a => a.questionId === o.questionId);
|
|
390
|
-
return answer || o;
|
|
391
|
-
}),
|
|
392
|
-
})),
|
|
393
|
-
};
|
|
394
|
-
if (!modifierBooking.unitItems.find(u => u.questionAnswers && u.questionAnswers.length)) {
|
|
395
|
-
modifierBooking = R.omit(['unitItems'], modifierBooking);
|
|
396
|
-
}
|
|
397
|
-
booking = R.path(['data'], await axios({
|
|
398
|
-
method: 'patch',
|
|
399
|
-
url: `${endpoint || this.endpoint}/bookings/${booking.uuid}`,
|
|
400
|
-
data: modifierBooking,
|
|
401
|
-
headers,
|
|
402
|
-
}));
|
|
403
|
-
}
|
|
404
402
|
// for booking update, we may not need to confirm again
|
|
405
403
|
if (!booking.utcConfirmedAt && !partialOrder) {
|
|
406
404
|
const dataForConfirmBooking = {
|
|
@@ -623,8 +621,6 @@ class Plugin {
|
|
|
623
621
|
},
|
|
624
622
|
query: {
|
|
625
623
|
productId,
|
|
626
|
-
date,
|
|
627
|
-
dateFormat,
|
|
628
624
|
},
|
|
629
625
|
}) {
|
|
630
626
|
const headers = getHeaders({
|
|
@@ -647,6 +643,7 @@ class Plugin {
|
|
|
647
643
|
return 'long';
|
|
648
644
|
})(),
|
|
649
645
|
options: o.selectOptions,
|
|
646
|
+
isPerUnitItem: o.isPerUnitItem,
|
|
650
647
|
});
|
|
651
648
|
if (!productId) {
|
|
652
649
|
const allProducts = R.pathOr([], ['data'], await axios({
|
|
@@ -655,13 +652,15 @@ class Plugin {
|
|
|
655
652
|
headers,
|
|
656
653
|
}));
|
|
657
654
|
const allOptions = R.chain(R.propOr([], 'options'), allProducts);
|
|
658
|
-
const allUnits = R.chain(R.propOr([], 'units'), allOptions);
|
|
655
|
+
const allUnits = R.chain(R.propOr([], 'units'), allOptions).map(o => ({ ...o, isPerUnitItem: true }));
|
|
659
656
|
const allQuestions = R.call(R.compose(
|
|
660
657
|
R.uniqBy(R.prop('id')),
|
|
661
|
-
R.chain(
|
|
658
|
+
R.chain(obj => (obj.questions || []).map(q => ({
|
|
659
|
+
...q,
|
|
660
|
+
isPerUnitItem: Boolean(obj.isPerUnitItem),
|
|
661
|
+
}))),
|
|
662
662
|
R.filter(o => o.questions && o.questions.length),
|
|
663
663
|
), [...allOptions, ...allUnits]);
|
|
664
|
-
console.log(allQuestions);
|
|
665
664
|
return {
|
|
666
665
|
fields: [],
|
|
667
666
|
customFields: allQuestions.map(convertQToField),
|
|
@@ -677,11 +676,14 @@ class Plugin {
|
|
|
677
676
|
const allOptions = R.propOr([], 'options', product);
|
|
678
677
|
const allQuestions = R.call(R.compose(
|
|
679
678
|
R.uniqBy(R.prop('id')),
|
|
680
|
-
R.chain(
|
|
679
|
+
R.chain(obj => (obj.questions || []).map(q => ({
|
|
680
|
+
...q,
|
|
681
|
+
isPerUnitItem: Boolean(obj.isPerUnitItem),
|
|
682
|
+
}))),
|
|
681
683
|
R.filter(o => o.questions && o.questions.length),
|
|
682
684
|
), [
|
|
683
685
|
...allOptions,
|
|
684
|
-
...R.chain(R.propOr([], 'units'), allOptions),
|
|
686
|
+
...R.chain(R.propOr([], 'units'), allOptions).map(o => ({ ...o, isPerUnitItem: true })),
|
|
685
687
|
]);
|
|
686
688
|
if (!product) return { fields: [] };
|
|
687
689
|
return {
|
package/package.json
CHANGED
|
@@ -27,8 +27,12 @@ const resolvers = {
|
|
|
27
27
|
dateTimeStart: root => R.path(['localDateTimeStart'], root) || R.path(['localDate'], root),
|
|
28
28
|
dateTimeEnd: root => R.path(['localDateTimeEnd'], root) || R.path(['localDate'], root),
|
|
29
29
|
allDay: R.path(['allDay']),
|
|
30
|
-
vacancies: R.
|
|
31
|
-
available: root =>
|
|
30
|
+
vacancies: R.propOr(99, 'vacancies'),
|
|
31
|
+
available: root => {
|
|
32
|
+
if (root.available === true) return true;
|
|
33
|
+
if (root.status === 'FREESALE') return true;
|
|
34
|
+
return root.status !== 'SOLD_OUT' && root.vacancies > 0;
|
|
35
|
+
},
|
|
32
36
|
offers: root => R.pathOr([], ['offers'], root).map(o => ({
|
|
33
37
|
offerId: o.code,
|
|
34
38
|
title: o.title,
|