tripstorekrabi-shared 1.10.0 → 1.10.2
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/booking.js +33 -0
- package/index.js +24 -1
- package/package.json +1 -1
package/booking.js
CHANGED
|
@@ -115,4 +115,37 @@ export function addBookingFromInvoice(firestore, admin, invoice, paymentData, co
|
|
|
115
115
|
);
|
|
116
116
|
});
|
|
117
117
|
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function getStartingPointMessage(booking) {
|
|
121
|
+
let text = booking.startingPointDescription;
|
|
122
|
+
if (booking.pickupTime.indexOf('-') != -1) {
|
|
123
|
+
text +=
|
|
124
|
+
' between ' +
|
|
125
|
+
booking.pickupTime.replace(' - ', ' and ').replace('-', ' and ');
|
|
126
|
+
} else {
|
|
127
|
+
text += ' at ' + booking.pickupTime;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
let date = dayjs(booking.departureDate.toDate()).format('Do MMM');
|
|
131
|
+
|
|
132
|
+
if (
|
|
133
|
+
dayjs().add(1, 'day').isSame(dayjs(booking.departureDate.toDate()), 'day')
|
|
134
|
+
) {
|
|
135
|
+
text += ' tomorrow the ' + date;
|
|
136
|
+
} else if (dayjs().isSame(dayjs(booking.departureDate.toDate()), 'day')) {
|
|
137
|
+
text += ' today the ' + date;
|
|
138
|
+
} else {
|
|
139
|
+
text += ' on the ' + date;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
text += '. Please watch out for the staff of ' + booking.operator + '.';
|
|
143
|
+
|
|
144
|
+
if (booking.specialRequirements) {
|
|
145
|
+
text +=
|
|
146
|
+
'\n\nSPECIAL REQUIREMENTS: ' +
|
|
147
|
+
booking.specialRequirements.toUpperCase();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return text;
|
|
118
151
|
}
|
package/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { ngraminator } from "ngraminator";
|
|
2
2
|
|
|
3
|
+
const PHONE_REGEXP = /[^\d+]/g;
|
|
4
|
+
|
|
3
5
|
export function build(docId, booking) {
|
|
4
6
|
let referenceNumber = [booking.referenceNumber];
|
|
5
7
|
if (booking.referenceNumber.indexOf("EXP-") != -1) {
|
|
@@ -72,8 +74,18 @@ export function build(docId, booking) {
|
|
|
72
74
|
data.pickupHotel = ngrams;
|
|
73
75
|
}
|
|
74
76
|
|
|
77
|
+
let phoneNumbers = [];
|
|
75
78
|
if (booking.phoneNumber) {
|
|
76
|
-
|
|
79
|
+
addPhoneNumbers(phoneNumbers, booking.phoneNumber);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (booking.phoneNumber2) {
|
|
83
|
+
addPhoneNumbers(phoneNumbers, booking.phoneNumber2);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
phoneNumbers = [...new Set(phoneNumbers)];
|
|
87
|
+
if (phoneNumbers.length > 0) {
|
|
88
|
+
data.phoneNumber = phoneNumbers;
|
|
77
89
|
}
|
|
78
90
|
|
|
79
91
|
return data;
|
|
@@ -82,4 +94,15 @@ export function build(docId, booking) {
|
|
|
82
94
|
function computeNgrams(value) {
|
|
83
95
|
let valueArray = value.split(" ").map(item => item.trim()).filter(item => item);
|
|
84
96
|
return ngraminator(valueArray, Array.from({ length: valueArray.length }, (_, i) => i + 1)).map(item => item.join(" "));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function addPhoneNumbers(phoneNumbers, phoneNumber) {
|
|
100
|
+
phoneNumber = phoneNumber.replace(PHONE_REGEXP, "");
|
|
101
|
+
if (phoneNumber.startsWith("+")) {
|
|
102
|
+
phoneNumbers.push(phoneNumber);
|
|
103
|
+
phoneNumbers.push(phoneNumber.substring(1));
|
|
104
|
+
} else {
|
|
105
|
+
phoneNumbers.push(phoneNumber);
|
|
106
|
+
phoneNumbers.push("+" + phoneNumber);
|
|
107
|
+
}
|
|
85
108
|
}
|