ti2-ventrata 1.0.32 → 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
 
@@ -332,15 +332,17 @@ class Plugin {
332
332
  endpoint,
333
333
  octoEnv,
334
334
  acceptLanguage,
335
- resellerId,
336
335
  },
337
336
  payload: {
337
+ orderId,
338
+ partialOrder,
338
339
  rebookingId,
339
340
  availabilityKey,
340
341
  holder,
341
342
  notes,
342
343
  reference,
343
344
  pickupPoint,
345
+ customFieldValues,
344
346
  },
345
347
  typeDefsAndQueries: {
346
348
  bookingTypeDefs,
@@ -355,22 +357,48 @@ class Plugin {
355
357
  endpoint,
356
358
  octoEnv,
357
359
  acceptLanguage,
358
- resellerId,
359
360
  });
360
361
  const dataForCreateBooking = await jwt.verify(availabilityKey, this.jwtKey);
361
362
  let booking = R.path(['data'], await axios({
362
363
  method: rebookingId ? 'patch' : 'post',
363
364
  url: `${endpoint || this.endpoint}/bookings${rebookingId ? `/${rebookingId}` : ''}`,
364
365
  data: {
365
- settlementMethod: 'DEFERRED',
366
+ orderId,
367
+ settlementMethod: reference ? 'VOUCHER' : 'DEFERRED',
366
368
  ...dataForCreateBooking,
367
369
  notes,
368
370
  ...(pickupPoint ? { pickupRequested: true, pickupPointId: pickupPoint } : {}),
369
371
  },
370
372
  headers,
371
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
+ }
372
400
  // for booking update, we may not need to confirm again
373
- if (!booking.utcConfirmedAt) {
401
+ if (!booking.utcConfirmedAt && !partialOrder) {
374
402
  const dataForConfirmBooking = {
375
403
  contact: {
376
404
  fullName: `${holder.name} ${holder.surname}`,
@@ -381,7 +409,7 @@ class Plugin {
381
409
  },
382
410
  notes,
383
411
  resellerReference: reference,
384
- settlementMethod: 'DEFERRED',
412
+ settlementMethod: reference ? 'VOUCHER' : 'DEFERRED',
385
413
  };
386
414
  booking = R.path(['data'], await axios({
387
415
  method: 'post',
@@ -580,11 +608,81 @@ class Plugin {
580
608
  }
581
609
 
582
610
  // eslint-disable-next-line class-methods-use-this
583
- async getCreateBookingFields() {
584
- 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: [] };
585
683
  return {
586
684
  fields: [],
587
- customFields,
685
+ customFields: allQuestions.map(convertQToField),
588
686
  };
589
687
  }
590
688
  }
package/index.test.js CHANGED
@@ -212,7 +212,8 @@ describe('search tests', () => {
212
212
  country: faker.address.countryCode(),
213
213
  locales: ['en-US', 'en', 'es'],
214
214
  },
215
- reference,
215
+ // our api key doesn't allow us to set the reference and settlementMethod as VOUCHER
216
+ // reference,
216
217
  },
217
218
  });
218
219
  expect(retVal.booking).toBeTruthy();
@@ -312,7 +313,7 @@ describe('search tests', () => {
312
313
  country: faker.address.countryCode(),
313
314
  locales: ['en-US', 'en', 'es'],
314
315
  },
315
- reference,
316
+ // reference,
316
317
  referrer: 'referrerforapitest',
317
318
  settlementMethod: 'DEFERRED',
318
319
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ti2-ventrata",
3
- "version": "1.0.32",
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,