ti2-ventrata 1.0.33 → 1.0.34

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,34 @@ 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
+ const 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
+ questionAnswers: u.questionAnswers.map(o => {
388
+ const answer = answers.find(a => a.questionId === o.questionId);
389
+ return answer || o;
390
+ }),
391
+ })).filter(u => u.questionAnswers.length),
392
+ };
393
+ booking = R.path(['data'], await axios({
394
+ method: 'patch',
395
+ url: `${endpoint || this.endpoint}/bookings/${booking.uuid}`,
396
+ data: modifierBooking,
397
+ headers,
398
+ }));
399
+ }
370
400
  // for booking update, we may not need to confirm again
371
- if (!booking.utcConfirmedAt) {
401
+ if (!booking.utcConfirmedAt && !partialOrder) {
372
402
  const dataForConfirmBooking = {
373
403
  contact: {
374
404
  fullName: `${holder.name} ${holder.surname}`,
@@ -578,11 +608,81 @@ class Plugin {
578
608
  }
579
609
 
580
610
  // eslint-disable-next-line class-methods-use-this
581
- async getCreateBookingFields() {
582
- const customFields = [];
611
+ async getCreateBookingFields({
612
+ axios,
613
+ token: {
614
+ apiKey,
615
+ endpoint,
616
+ octoEnv,
617
+ acceptLanguage,
618
+ resellerId,
619
+ },
620
+ query: {
621
+ productId,
622
+ date,
623
+ dateFormat,
624
+ },
625
+ }) {
626
+ const headers = getHeaders({
627
+ apiKey,
628
+ endpoint,
629
+ octoEnv,
630
+ acceptLanguage,
631
+ resellerId,
632
+ });
633
+ const convertQToField = o => ({
634
+ id: o.id,
635
+ subtitle: o.description === o.label ? '' : o.description,
636
+ title: o.label,
637
+ type: (() => {
638
+ if (o.inputType === 'radio') return 'radio';
639
+ if (Array.isArray(o.selectOptions) && o.selectOptions.length) return 'extended-option';
640
+ if (o.inputType === 'number') return 'count';
641
+ if (o.inputType === 'text') return 'long';
642
+ if (o.inputType === 'textarea') return 'long';
643
+ return 'long';
644
+ })(),
645
+ options: o.selectOptions,
646
+ });
647
+ if (!productId) {
648
+ const allProducts = R.pathOr([], ['data'], await axios({
649
+ method: 'get',
650
+ url: `${endpoint || this.endpoint}/products`,
651
+ headers,
652
+ }));
653
+ const allOptions = R.chain(R.propOr([], 'options'), allProducts);
654
+ const allUnits = R.chain(R.propOr([], 'units'), allOptions);
655
+ const allQuestions = R.call(R.compose(
656
+ R.uniqBy(R.prop('id')),
657
+ R.chain(R.propOr([], 'questions')),
658
+ R.filter(o => o.questions && o.questions.length),
659
+ ), [...allOptions, ...allUnits]);
660
+ console.log(allQuestions);
661
+ return {
662
+ fields: [],
663
+ customFields: allQuestions.map(convertQToField),
664
+ };
665
+ }
666
+ const url = `${endpoint || this.endpoint}/products/${productId}`;
667
+ const product = R.pathOr([], ['data'], await axios({
668
+ method: 'get',
669
+ url,
670
+ headers,
671
+ }));
672
+
673
+ const allOptions = R.propOr([], 'options', product);
674
+ const allQuestions = R.call(R.compose(
675
+ R.uniqBy(R.prop('id')),
676
+ R.chain(R.propOr([], 'questions')),
677
+ R.filter(o => o.questions && o.questions.length),
678
+ ), [
679
+ ...allOptions,
680
+ ...R.chain(R.propOr([], 'units'), allOptions),
681
+ ]);
682
+ if (!product) return { fields: [] };
583
683
  return {
584
684
  fields: [],
585
- customFields,
685
+ customFields: allQuestions.map(convertQToField),
586
686
  };
587
687
  }
588
688
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ti2-ventrata",
3
- "version": "1.0.33",
3
+ "version": "1.0.34",
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,