tripstorekrabi-shared 1.24.6 → 1.24.8

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 +17 -5
  2. package/package.json +4 -4
package/booking.js CHANGED
@@ -23,11 +23,12 @@ export function addBookingFromInvoice(
23
23
  firestore,
24
24
  invoice,
25
25
  paymentData,
26
- comment = ''
26
+ comment = '',
27
+ existingTransaction = null
27
28
  ) {
28
29
  let bookingNumberDoc = firestore.collection('meta').doc('BOOKING_NUMBER');
29
30
 
30
- return firestore.runTransaction(async (transaction) => {
31
+ const coreLogic = async (transaction) => {
31
32
  const snapshot = await transaction.get(bookingNumberDoc);
32
33
  const currentLast = snapshot.get('last') ?? 0;
33
34
 
@@ -112,7 +113,6 @@ export function addBookingFromInvoice(
112
113
 
113
114
  if (item.startingPointId) data.startingPointId = item.startingPointId;
114
115
  if (item.dropoffHotel && item.dropoffHotel.length > 0) data.dropoffHotel = item.dropoffHotel;
115
- if (i > 0) data.partnerNetPrice = 0;
116
116
  if (item.nationalParkFee) data.nationalParkFee = item.nationalParkFee;
117
117
  if (item.tourGuideLanguage) data.tourGuideLanguage = item.tourGuideLanguage;
118
118
 
@@ -125,13 +125,17 @@ export function addBookingFromInvoice(
125
125
  }
126
126
  if (endPointId) data.endPointId = endPointId;
127
127
 
128
+ data = { ...data, ...paymentData };
129
+
128
130
  if (productSnapshot) {
129
131
  data.operatorNetPrice = calculateTotalOperatorPrice(data, productSnapshot.data());
130
132
  } else {
131
133
  data.operatorNetPrice = 0;
132
134
  }
133
135
 
134
- data = { ...data, ...paymentData };
136
+ if (i > 0) {
137
+ data.partnerNetPrice = 0;
138
+ }
135
139
 
136
140
  let doc = firestore.collection('bookings').doc();
137
141
  transaction.set(doc, data);
@@ -143,7 +147,15 @@ export function addBookingFromInvoice(
143
147
  { last: currentLast + processed },
144
148
  { merge: true }
145
149
  );
146
- });
150
+
151
+ return processed;
152
+ };
153
+
154
+ if (existingTransaction) {
155
+ return coreLogic(existingTransaction);
156
+ } else {
157
+ return firestore.runTransaction(coreLogic);
158
+ }
147
159
  }
148
160
 
149
161
  export function getOperatorSignature(agent, operatorName, contact) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tripstorekrabi-shared",
3
- "version": "1.24.6",
3
+ "version": "1.24.8",
4
4
  "description": "Shared library for Trip Store Krabi",
5
5
  "author": "Stefan Sommer <tonprince@gmail.com>",
6
6
  "repository": {
@@ -18,9 +18,9 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "dayjs": "^1.11.21",
21
- "libphonenumber-js": "^1.13.7",
22
- "nanoid": "^5.1.16",
23
- "firebase-admin": "^14.1.0"
21
+ "libphonenumber-js": "^1.13.10",
22
+ "nanoid": "^6.0.1",
23
+ "firebase-admin": "^14.2.0"
24
24
  },
25
25
  "scripts": {
26
26
  "deploy": "npm publish"