ti2-ventrata 1.0.33 → 1.0.35

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 CHANGED
@@ -24,7 +24,7 @@ const getHeaders = ({
24
24
  ...acceptLanguage ? { 'Accept-Language': acceptLanguage } : {},
25
25
  'Content-Type': 'application/json',
26
26
  // ...resellerId ? { Referer: resellerId } : {},+
27
- 'Octo-Capabilities': 'octo/pricing,octo/pickups,octo/cart,octo/offers',
27
+ 'Octo-Capabilities': 'octo/pricing,octo/pickups,octo/cart,octo/offers,octo/questions',
28
28
  // 'Octo-Capabilities': 'octo/pricing',
29
29
  });
30
30
 
@@ -334,12 +334,15 @@ class Plugin {
334
334
  acceptLanguage,
335
335
  },
336
336
  payload: {
337
+ orderId,
338
+ partialOrder,
337
339
  rebookingId,
338
340
  availabilityKey,
339
341
  holder,
340
342
  notes,
341
343
  reference,
342
344
  pickupPoint,
345
+ customFieldValues,
343
346
  },
344
347
  typeDefsAndQueries: {
345
348
  bookingTypeDefs,
@@ -360,6 +363,7 @@ class Plugin {
360
363
  method: rebookingId ? 'patch' : 'post',
361
364
  url: `${endpoint || this.endpoint}/bookings${rebookingId ? `/${rebookingId}` : ''}`,
362
365
  data: {
366
+ orderId,
363
367
  settlementMethod: reference ? 'VOUCHER' : 'DEFERRED',
364
368
  ...dataForCreateBooking,
365
369
  notes,
@@ -367,8 +371,38 @@ class Plugin {
367
371
  },
368
372
  headers,
369
373
  }));
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
+ }
370
404
  // for booking update, we may not need to confirm again
371
- if (!booking.utcConfirmedAt) {
405
+ if (!booking.utcConfirmedAt && !partialOrder) {
372
406
  const dataForConfirmBooking = {
373
407
  contact: {
374
408
  fullName: `${holder.name} ${holder.surname}`,
@@ -578,11 +612,81 @@ class Plugin {
578
612
  }
579
613
 
580
614
  // eslint-disable-next-line class-methods-use-this
581
- async getCreateBookingFields() {
582
- const customFields = [];
615
+ async getCreateBookingFields({
616
+ axios,
617
+ token: {
618
+ apiKey,
619
+ endpoint,
620
+ octoEnv,
621
+ acceptLanguage,
622
+ resellerId,
623
+ },
624
+ query: {
625
+ productId,
626
+ date,
627
+ dateFormat,
628
+ },
629
+ }) {
630
+ const headers = getHeaders({
631
+ apiKey,
632
+ endpoint,
633
+ octoEnv,
634
+ acceptLanguage,
635
+ resellerId,
636
+ });
637
+ const convertQToField = o => ({
638
+ id: o.id,
639
+ subtitle: o.description === o.label ? '' : o.description,
640
+ title: o.label,
641
+ type: (() => {
642
+ if (o.inputType === 'radio') return 'radio';
643
+ if (Array.isArray(o.selectOptions) && o.selectOptions.length) return 'extended-option';
644
+ if (o.inputType === 'number') return 'count';
645
+ if (o.inputType === 'text') return 'long';
646
+ if (o.inputType === 'textarea') return 'long';
647
+ return 'long';
648
+ })(),
649
+ options: o.selectOptions,
650
+ });
651
+ if (!productId) {
652
+ const allProducts = R.pathOr([], ['data'], await axios({
653
+ method: 'get',
654
+ url: `${endpoint || this.endpoint}/products`,
655
+ headers,
656
+ }));
657
+ const allOptions = R.chain(R.propOr([], 'options'), allProducts);
658
+ const allUnits = R.chain(R.propOr([], 'units'), allOptions);
659
+ const allQuestions = R.call(R.compose(
660
+ R.uniqBy(R.prop('id')),
661
+ R.chain(R.propOr([], 'questions')),
662
+ R.filter(o => o.questions && o.questions.length),
663
+ ), [...allOptions, ...allUnits]);
664
+ console.log(allQuestions);
665
+ return {
666
+ fields: [],
667
+ customFields: allQuestions.map(convertQToField),
668
+ };
669
+ }
670
+ const url = `${endpoint || this.endpoint}/products/${productId}`;
671
+ const product = R.pathOr([], ['data'], await axios({
672
+ method: 'get',
673
+ url,
674
+ headers,
675
+ }));
676
+
677
+ const allOptions = R.propOr([], 'options', product);
678
+ const allQuestions = R.call(R.compose(
679
+ R.uniqBy(R.prop('id')),
680
+ R.chain(R.propOr([], 'questions')),
681
+ R.filter(o => o.questions && o.questions.length),
682
+ ), [
683
+ ...allOptions,
684
+ ...R.chain(R.propOr([], 'units'), allOptions),
685
+ ]);
686
+ if (!product) return { fields: [] };
583
687
  return {
584
688
  fields: [],
585
- customFields,
689
+ customFields: allQuestions.map(convertQToField),
586
690
  };
587
691
  }
588
692
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ti2-ventrata",
3
- "version": "1.0.33",
3
+ "version": "1.0.35",
4
4
  "description": "Ventrata's TI2 Plugin",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -11,7 +11,8 @@ const resolvers = {
11
11
  Query: {
12
12
  id: R.path(['id']),
13
13
  bookingId: R.path(['id']),
14
- orderId: R.path(['orderReference']),
14
+ orderId: R.path(['orderId']),
15
+ orderReference: R.path(['orderReference']),
15
16
  supplierBookingId: R.path(['supplierReference']),
16
17
  resellerReference: R.propOr('', 'resellerReference'),
17
18
  status: e => capitalize(R.path(['status'], e)),
@@ -29,11 +30,11 @@ const resolvers = {
29
30
  allDay: R.path(['availability', 'allDay']),
30
31
  bookingDate: R.path(['utcCreatedAt']),
31
32
  holder: root => ({
32
- name: R.path(['contact', 'fullName'], root).split(' ')[0],
33
- surname: R.last(R.path(['contact', 'fullName'], root).split(' ')),
34
- fullName: R.path(['contact', 'fullName'], root),
35
- phoneNumber: R.path(['contact', 'phoneNumber'], root),
36
- emailAddress: R.path(['contact', 'emailAddress'], root),
33
+ name: R.pathOr('', ['contact', 'fullName'], root).split(' ')[0],
34
+ surname: R.last(R.pathOr('', ['contact', 'fullName'], root).split(' ')),
35
+ fullName: R.pathOr('', ['contact', 'fullName'], root),
36
+ phoneNumber: R.pathOr('', ['contact', 'phoneNumber'], root),
37
+ emailAddress: R.pathOr('', ['contact', 'emailAddress'], root),
37
38
  }),
38
39
  notes: root => root.notes || '',
39
40
  price: root => root.pricing,