tripstorekrabi-shared 1.19.1 → 1.19.3

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.
Files changed (2) hide show
  1. package/booking.js +92 -1
  2. package/package.json +1 -1
package/booking.js CHANGED
@@ -4,7 +4,7 @@ import utc from 'dayjs/plugin/utc.js';
4
4
  import timezone from 'dayjs/plugin/timezone.js';
5
5
  import { PAY_ON_TOUR, calculateTotalOperatorPrice } from './price.js';
6
6
  import { nanoid } from 'nanoid';
7
- import { isHotelPickup } from './utils.js';
7
+ import { CHECK_IN_LATE, IN_HOUSE, isAirportDropOff, isAirportPickup, isHotelPickup, isTrainStation, KEEP_PRIVATE, NO_PICKUP_HOTEL_YET, NO_ROOM, STAY_NEARBY } from './utils.js';
8
8
 
9
9
  dayjs.extend(advancedFormat);
10
10
  dayjs.extend(utc);
@@ -362,4 +362,95 @@ export function hasFood(product) {
362
362
  item = item.toLowerCase();
363
363
  return item.includes('breakfast') || item.includes('lunch') || item.includes('brunch') || item.includes('dinner');
364
364
  }) != null;
365
+ }
366
+
367
+ export function createTodos(booking, product) {
368
+ let todos = {};
369
+
370
+ let pastTravelDate = dayjs(booking.departureDate.toDate()).isSameOrBefore(
371
+ dayjs().startOf('day'),
372
+ 'day'
373
+ );
374
+
375
+ let customerBookingStatus = booking.customerBookingStatus;
376
+ if (customerBookingStatus !== 'Canceled') {
377
+ // check pickup hotel and room number
378
+ if (isHotelPickup(booking.startingPointDescription)) {
379
+ if (booking.startingPointDescription === NO_PICKUP_HOTEL_YET) {
380
+ todos.pickupHotel = "missing";
381
+ }
382
+
383
+ if (
384
+ booking.roomNumber !== NO_ROOM &&
385
+ booking.roomNumber !== IN_HOUSE &&
386
+ booking.roomNumber !== STAY_NEARBY &&
387
+ booking.roomNumber !== KEEP_PRIVATE &&
388
+ (!booking.roomNumber || booking.roomNumber === CHECK_IN_LATE)
389
+ ) {
390
+ todos.roomNumber = "missing";
391
+ } else if (
392
+ !booking.roomConfirmed &&
393
+ booking.roomNumber !== NO_ROOM &&
394
+ booking.roomNumber !== IN_HOUSE &&
395
+ booking.roomNumber !== STAY_NEARBY &&
396
+ booking.roomNumber !== KEEP_PRIVATE &&
397
+ booking.roomNumber !== CHECK_IN_LATE &&
398
+ booking.sentToOperator === true
399
+ && !pastTravelDate
400
+ ) {
401
+ todos.roomNumber = "sendToOperator";
402
+ }
403
+ }
404
+
405
+ if (product && hasFood(product) && !pastTravelDate) {
406
+ if (!booking.dietary) {
407
+ todos.dietary = "missing";
408
+ } else if (!booking.dietaryConfirmed && booking.dietary?.length > 0 && booking.dietary !== 'None' && booking.sentToOperator === true) {
409
+ todos.dietary = "sendToOperator";
410
+ }
411
+ }
412
+
413
+ // hotel dropoff
414
+ if (booking.productDescription.includes('with transfer to hotel')) {
415
+ if ((booking.dropoffHotel ?? "").length === 0) {
416
+ todos.dropoffHotel = "missing";
417
+ } else if (!booking.dropoffHotelConfirmed) {
418
+ todos.dropoffHotel = "sendToOperator";
419
+ }
420
+ }
421
+
422
+ if (isAirportPickup(booking.startingPointDescription)) {
423
+ if (!booking.flight) {
424
+ todos.inboundFlightDetails = "missing";
425
+ } else if (!booking.flightConfirmed) {
426
+ todos.inboundFlightDetails = "sendToOperator";
427
+ }
428
+ }
429
+
430
+ if (isAirportDropOff(booking.productDescription)) {
431
+ if (!booking.flight) {
432
+ todos.outboundFlightDetails = "missing";
433
+ } else if (!booking.flightConfirmed) {
434
+ todos.outboundFlightDetails = "sendToOperator";
435
+ }
436
+ }
437
+
438
+ if (isTrainStation(booking.startingPointDescription)) {
439
+ if (!booking.train) {
440
+ todos.inboundTrainDetails = "missing";
441
+ } else if (!booking.trainConfirmed) {
442
+ todos.inboundTrainDetails = "sendToOperator";
443
+ }
444
+ }
445
+
446
+ if (isTrainStation(booking.productDescription)) {
447
+ if (!booking.train) {
448
+ todos.outboundTrainDetails = "missing";
449
+ } else if (!booking.trainConfirmed) {
450
+ todos.outboundTrainDetails = "sendToOperator";
451
+ }
452
+ }
453
+ }
454
+
455
+ return todos;
365
456
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tripstorekrabi-shared",
3
- "version": "1.19.1",
3
+ "version": "1.19.3",
4
4
  "description": "Shared library for Trip Store Krabi",
5
5
  "author": "Stefan Sommer <tonprince@gmail.com>",
6
6
  "repository": {