@driveflux/api-functions 0.0.6 → 0.0.7-next.1

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 (53) hide show
  1. package/dist/auth/confirm.js +73 -327
  2. package/dist/auth/emails.js +43 -210
  3. package/dist/auth/formatter.js +11 -11
  4. package/dist/auth/otp.js +122 -392
  5. package/dist/auth/register.js +100 -396
  6. package/dist/auth/tokens.d.ts +3 -3
  7. package/dist/auth/tokens.js +115 -430
  8. package/dist/auth/verifications.d.ts.map +1 -1
  9. package/dist/auth/verifications.js +191 -514
  10. package/dist/auth/verifications.js.map +1 -1
  11. package/dist/constants.js +5 -4
  12. package/dist/mailjet/calls/manage-contacts-in-list.js +22 -166
  13. package/dist/mailjet/calls/manage-subscription-status.js +13 -153
  14. package/dist/mailjet/calls/request-service.d.ts +1 -1
  15. package/dist/mailjet/calls/request-service.d.ts.map +1 -1
  16. package/dist/mailjet/calls/request-service.js +18 -183
  17. package/dist/mailjet/refresh-email-preferences.js +26 -225
  18. package/dist/mailjet/set-contact.js +23 -214
  19. package/dist/mailjet/types.js +2 -1
  20. package/dist/mailjet/utils/convert-to-array.js +9 -58
  21. package/dist/mailjet/utils/extract-email-preferences.js +41 -217
  22. package/dist/mailjet/utils/lists.js +30 -249
  23. package/dist/mailjet/utils/update-email-references.js +27 -208
  24. package/dist/notion/client.js +48 -197
  25. package/dist/notion/helpful.js +29 -170
  26. package/dist/notion/schemas/block.js +49 -43
  27. package/dist/notion/schemas/common.js +17 -14
  28. package/dist/notion/schemas/database.js +125 -159
  29. package/dist/notion/schemas/emoji.js +3 -2
  30. package/dist/notion/schemas/file.js +10 -10
  31. package/dist/notion/schemas/kb.js +9 -8
  32. package/dist/notion/schemas/page.js +126 -171
  33. package/dist/notion/schemas/parent.js +9 -8
  34. package/dist/notion/schemas/user.js +21 -20
  35. package/dist/reservation/agree.js +19 -158
  36. package/dist/reservation/checks.js +23 -178
  37. package/dist/reservation/display-vehicle.d.ts +37 -37
  38. package/dist/reservation/display-vehicle.d.ts.map +1 -1
  39. package/dist/reservation/display-vehicle.js +142 -514
  40. package/dist/reservation/fetch-or-create.js +197 -482
  41. package/dist/reservation/invoice.js +198 -496
  42. package/dist/reservation/payer.js +28 -177
  43. package/dist/reservation/reserve.js +31 -191
  44. package/dist/reservation/types.js +2 -1
  45. package/dist/reservation/vehicle.js +24 -186
  46. package/dist/slack.d.ts +2 -2
  47. package/dist/slack.d.ts.map +1 -1
  48. package/dist/slack.js +67 -273
  49. package/dist/validation.js +81 -139
  50. package/dist/vehicle/vehicle-pricing/constants.js +33 -36
  51. package/dist/vehicle/vehicle-pricing/index.js +99 -257
  52. package/dist/vehicle/vehicle-pricing/types.js +2 -1
  53. package/package.json +12 -12
@@ -1,492 +1,207 @@
1
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
1
+ import { prisma, } from '@driveflux/db';
2
+ import { generateId } from '@driveflux/db/id';
3
+ import { reportError } from '@driveflux/reporter';
4
+ import { Ok } from '@driveflux/result';
5
+ import { slackLater } from '../slack';
6
+ import { createReservationInvoice, updateReservationInvoiceIfNeeded, } from './invoice';
7
+ export const fetchOrCreateReservation = async ({ vehicle, payer, body, }) => {
8
+ const { subscribingUser, plan, mileagePackage, couponCode, referralCode, asBusiness, source, deliveryAddresses, deliveryDate, analytics, paymentIntentId, freeReservation, freeReservationReason, } = body;
2
9
  try {
3
- var info = gen[key](arg);
4
- var value = info.value;
5
- } catch (error) {
6
- reject(error);
7
- return;
8
- }
9
- if (info.done) {
10
- resolve(value);
11
- } else {
12
- Promise.resolve(value).then(_next, _throw);
13
- }
14
- }
15
- function _async_to_generator(fn) {
16
- return function() {
17
- var self = this, args = arguments;
18
- return new Promise(function(resolve, reject) {
19
- var gen = fn.apply(self, args);
20
- function _next(value) {
21
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
10
+ const previousReservation = await prisma.subscriptionReservation.findFirst({
11
+ where: {
12
+ userId: subscribingUser.id,
13
+ vehicleId: vehicle.id,
14
+ plan,
15
+ mileagePackage,
16
+ couponCode,
17
+ referralCode,
18
+ asBusiness: !!asBusiness,
19
+ source,
20
+ // If the subscription ID was populated, this means that this reservation was consumed into a subsription,
21
+ // so we shouldn't re-use it
22
+ subscription: null,
23
+ },
24
+ orderBy: {
25
+ updatedAt: 'desc',
26
+ },
27
+ include: {
28
+ invoice: {
29
+ select: {
30
+ id: true,
31
+ voided: true,
32
+ stripePaymentIntentId: true,
33
+ couponCode: true,
34
+ payerId: true,
35
+ discountIds: true,
36
+ lines: true,
37
+ status: true,
38
+ lockedAt: true,
39
+ unlockAt: true,
40
+ locked: true,
41
+ },
42
+ },
43
+ },
44
+ });
45
+ if (previousReservation) {
46
+ if (previousReservation.invoice.voided) {
47
+ return recreateReservationInvoiceAndUpdateReservation(previousReservation, body, vehicle, payer);
22
48
  }
23
- function _throw(err) {
24
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
49
+ // If the invoice is paid or partially paid, this is a serious problem,
50
+ // we need to make a notification about this and recreate the invoice
51
+ const wrongStatuses = [
52
+ 'paid',
53
+ 'partiallyPaid',
54
+ 'partiallyRefunded',
55
+ 'refunded',
56
+ 'pendingRefund',
57
+ ];
58
+ if (wrongStatuses.includes(previousReservation.invoice.status)) {
59
+ const updatedReservation = await recreateReservationInvoiceAndUpdateReservation(previousReservation, body, vehicle, payer);
60
+ if (updatedReservation.err) {
61
+ return updatedReservation;
62
+ }
63
+ slackLater([
64
+ {
65
+ type: 'header',
66
+ text: {
67
+ type: 'plain_text',
68
+ text: '‼️ Reservation invoice in wrong status',
69
+ emoji: true,
70
+ },
71
+ },
72
+ {
73
+ type: 'section',
74
+ text: {
75
+ type: 'plain_text',
76
+ text: `The reservation invoice ${previousReservation.invoice.id} was in a wrong status (${previousReservation.invoice.status}), it was discarded and a new invoice (${updatedReservation.val.id}) was created, however, investigate the issue.`,
77
+ },
78
+ },
79
+ ]);
80
+ return updatedReservation;
25
81
  }
26
- _next(undefined);
27
- });
28
- };
29
- }
30
- function _define_property(obj, key, value) {
31
- if (key in obj) {
32
- Object.defineProperty(obj, key, {
33
- value: value,
34
- enumerable: true,
35
- configurable: true,
36
- writable: true
37
- });
38
- } else {
39
- obj[key] = value;
40
- }
41
- return obj;
42
- }
43
- function _object_spread(target) {
44
- for(var i = 1; i < arguments.length; i++){
45
- var source = arguments[i] != null ? arguments[i] : {};
46
- var ownKeys = Object.keys(source);
47
- if (typeof Object.getOwnPropertySymbols === "function") {
48
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
49
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
50
- }));
51
- }
52
- ownKeys.forEach(function(key) {
53
- _define_property(target, key, source[key]);
54
- });
55
- }
56
- return target;
57
- }
58
- function ownKeys(object, enumerableOnly) {
59
- var keys = Object.keys(object);
60
- if (Object.getOwnPropertySymbols) {
61
- var symbols = Object.getOwnPropertySymbols(object);
62
- if (enumerableOnly) {
63
- symbols = symbols.filter(function(sym) {
64
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
65
- });
82
+ // If the payment intent ID is different, we need to update it
83
+ const updated = await updateReservationInvoiceIfNeeded(previousReservation.invoice, body);
84
+ if (updated.err) {
85
+ return updated;
86
+ }
87
+ // Otherwise, we need to create a new reservation
88
+ return new Ok(previousReservation);
66
89
  }
67
- keys.push.apply(keys, symbols);
68
90
  }
69
- return keys;
70
- }
71
- function _object_spread_props(target, source) {
72
- source = source != null ? source : {};
73
- if (Object.getOwnPropertyDescriptors) {
74
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
75
- } else {
76
- ownKeys(Object(source)).forEach(function(key) {
77
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
78
- });
91
+ catch (error) {
92
+ // We couldn't fetch the reservation, so we create a new one and just log this
93
+ await reportError(error);
79
94
  }
80
- return target;
81
- }
82
- function _ts_generator(thisArg, body) {
83
- var f, y, t, _ = {
84
- label: 0,
85
- sent: function() {
86
- if (t[0] & 1) throw t[1];
87
- return t[1];
88
- },
89
- trys: [],
90
- ops: []
91
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
92
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
93
- return this;
94
- }), g;
95
- function verb(n) {
96
- return function(v) {
97
- return step([
98
- n,
99
- v
100
- ]);
101
- };
95
+ const reservationId = generateId('SubscriptionReservation');
96
+ // Create the reservation invoice
97
+ const invoiceResult = await createReservationInvoice({
98
+ couponCode,
99
+ plan,
100
+ mileagePackage,
101
+ referralCode,
102
+ reservationId,
103
+ paymentIntentId,
104
+ freeReservation,
105
+ freeReservationReason,
106
+ analytics,
107
+ vehicle,
108
+ payer,
109
+ subscribingUser,
110
+ });
111
+ if (invoiceResult.err) {
112
+ return invoiceResult;
102
113
  }
103
- function step(op) {
104
- if (f) throw new TypeError("Generator is already executing.");
105
- while(g && (g = 0, op[0] && (_ = 0)), _)try {
106
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
107
- if (y = 0, t) op = [
108
- op[0] & 2,
109
- t.value
110
- ];
111
- switch(op[0]){
112
- case 0:
113
- case 1:
114
- t = op;
115
- break;
116
- case 4:
117
- _.label++;
118
- return {
119
- value: op[1],
120
- done: false
121
- };
122
- case 5:
123
- _.label++;
124
- y = op[1];
125
- op = [
126
- 0
127
- ];
128
- continue;
129
- case 7:
130
- op = _.ops.pop();
131
- _.trys.pop();
132
- continue;
133
- default:
134
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
135
- _ = 0;
136
- continue;
137
- }
138
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
139
- _.label = op[1];
140
- break;
141
- }
142
- if (op[0] === 6 && _.label < t[1]) {
143
- _.label = t[1];
144
- t = op;
145
- break;
146
- }
147
- if (t && _.label < t[2]) {
148
- _.label = t[2];
149
- _.ops.push(op);
150
- break;
151
- }
152
- if (t[2]) _.ops.pop();
153
- _.trys.pop();
154
- continue;
155
- }
156
- op = body.call(thisArg, _);
157
- } catch (e) {
158
- op = [
159
- 6,
160
- e
161
- ];
162
- y = 0;
163
- } finally{
164
- f = t = 0;
165
- }
166
- if (op[0] & 5) throw op[1];
167
- return {
168
- value: op[0] ? op[1] : void 0,
169
- done: true
170
- };
171
- }
172
- }
173
- import { prisma } from '@driveflux/db';
174
- import { generateId } from '@driveflux/db/id';
175
- import { reportError } from '@driveflux/reporter';
176
- import { Ok } from '@driveflux/result';
177
- import { slackLater } from '../slack';
178
- import { createReservationInvoice, updateReservationInvoiceIfNeeded } from './invoice';
179
- export var fetchOrCreateReservation = function(param) {
180
- var vehicle = param.vehicle, payer = param.payer, body = param.body;
181
- return _async_to_generator(function() {
182
- var subscribingUser, plan, mileagePackage, couponCode, referralCode, asBusiness, source, deliveryAddresses, deliveryDate, analytics, paymentIntentId, freeReservation, freeReservationReason, previousReservation, wrongStatuses, updatedReservation, updated, error, reservationId, invoiceResult, reservation;
183
- return _ts_generator(this, function(_state) {
184
- switch(_state.label){
185
- case 0:
186
- subscribingUser = body.subscribingUser, plan = body.plan, mileagePackage = body.mileagePackage, couponCode = body.couponCode, referralCode = body.referralCode, asBusiness = body.asBusiness, source = body.source, deliveryAddresses = body.deliveryAddresses, deliveryDate = body.deliveryDate, analytics = body.analytics, paymentIntentId = body.paymentIntentId, freeReservation = body.freeReservation, freeReservationReason = body.freeReservationReason;
187
- _state.label = 1;
188
- case 1:
189
- _state.trys.push([
190
- 1,
191
- 7,
192
- ,
193
- 9
194
- ]);
195
- return [
196
- 4,
197
- prisma.subscriptionReservation.findFirst({
198
- where: {
199
- userId: subscribingUser.id,
200
- vehicleId: vehicle.id,
201
- plan: plan,
202
- mileagePackage: mileagePackage,
203
- couponCode: couponCode,
204
- referralCode: referralCode,
205
- asBusiness: !!asBusiness,
206
- source: source,
207
- // If the subscription ID was populated, this means that this reservation was consumed into a subsription,
208
- // so we shouldn't re-use it
209
- subscription: null
210
- },
211
- orderBy: {
212
- updatedAt: 'desc'
213
- },
214
- include: {
215
- invoice: {
216
- select: {
217
- id: true,
218
- voided: true,
219
- stripePaymentIntentId: true,
220
- couponCode: true,
221
- payerId: true,
222
- discountIds: true,
223
- lines: true,
224
- status: true,
225
- lockedAt: true,
226
- unlockAt: true,
227
- locked: true
228
- }
229
- }
230
- }
231
- })
232
- ];
233
- case 2:
234
- previousReservation = _state.sent();
235
- if (!previousReservation) return [
236
- 3,
237
- 6
238
- ];
239
- if (previousReservation.invoice.voided) {
240
- return [
241
- 2,
242
- recreateReservationInvoiceAndUpdateReservation(previousReservation, body, vehicle, payer)
243
- ];
244
- }
245
- // If the invoice is paid or partially paid, this is a serious problem,
246
- // we need to make a notification about this and recreate the invoice
247
- wrongStatuses = [
248
- 'paid',
249
- 'partiallyPaid',
250
- 'partiallyRefunded',
251
- 'refunded',
252
- 'pendingRefund'
253
- ];
254
- if (!wrongStatuses.includes(previousReservation.invoice.status)) return [
255
- 3,
256
- 4
257
- ];
258
- return [
259
- 4,
260
- recreateReservationInvoiceAndUpdateReservation(previousReservation, body, vehicle, payer)
261
- ];
262
- case 3:
263
- updatedReservation = _state.sent();
264
- if (updatedReservation.err) {
265
- return [
266
- 2,
267
- updatedReservation
268
- ];
269
- }
270
- slackLater([
271
- {
272
- type: 'header',
273
- text: {
274
- type: 'plain_text',
275
- text: '‼️ Reservation invoice in wrong status',
276
- emoji: true
277
- }
278
- },
279
- {
280
- type: 'section',
281
- text: {
282
- type: 'plain_text',
283
- text: "The reservation invoice ".concat(previousReservation.invoice.id, " was in a wrong status (").concat(previousReservation.invoice.status, "), it was discarded and a new invoice (").concat(updatedReservation.val.id, ") was created, however, investigate the issue.")
284
- }
285
- }
286
- ]);
287
- return [
288
- 2,
289
- updatedReservation
290
- ];
291
- case 4:
292
- return [
293
- 4,
294
- updateReservationInvoiceIfNeeded(previousReservation.invoice, body)
295
- ];
296
- case 5:
297
- updated = _state.sent();
298
- if (updated.err) {
299
- return [
300
- 2,
301
- updated
302
- ];
303
- }
304
- // Otherwise, we need to create a new reservation
305
- return [
306
- 2,
307
- new Ok(previousReservation)
308
- ];
309
- case 6:
310
- return [
311
- 3,
312
- 9
313
- ];
314
- case 7:
315
- error = _state.sent();
316
- // We couldn't fetch the reservation, so we create a new one and just log this
317
- return [
318
- 4,
319
- reportError(error)
320
- ];
321
- case 8:
322
- _state.sent();
323
- return [
324
- 3,
325
- 9
326
- ];
327
- case 9:
328
- reservationId = generateId('SubscriptionReservation');
329
- return [
330
- 4,
331
- createReservationInvoice({
332
- couponCode: couponCode,
333
- plan: plan,
334
- mileagePackage: mileagePackage,
335
- referralCode: referralCode,
336
- reservationId: reservationId,
337
- paymentIntentId: paymentIntentId,
338
- freeReservation: freeReservation,
339
- freeReservationReason: freeReservationReason,
340
- analytics: analytics,
341
- vehicle: vehicle,
342
- payer: payer,
343
- subscribingUser: subscribingUser
344
- })
345
- ];
346
- case 10:
347
- invoiceResult = _state.sent();
348
- if (invoiceResult.err) {
349
- return [
350
- 2,
351
- invoiceResult
352
- ];
353
- }
354
- return [
355
- 4,
356
- createReservation({
357
- reservationId: reservationId,
358
- invoiceId: invoiceResult.val.id,
359
- subscribingUserId: subscribingUser.id,
360
- vehicleId: vehicle.id,
361
- businessId: payer.object === 'business' ? payer.id : undefined,
362
- plan: plan,
363
- mileagePackage: mileagePackage,
364
- couponCode: couponCode,
365
- referralCode: referralCode,
366
- analytics: analytics,
367
- deliveryAddresses: deliveryAddresses,
368
- deliveryDate: deliveryDate,
369
- asBusiness: asBusiness,
370
- source: source
371
- })
372
- ];
373
- case 11:
374
- reservation = _state.sent();
375
- return [
376
- 2,
377
- new Ok(reservation)
378
- ];
379
- }
380
- });
381
- })();
114
+ const reservation = await createReservation({
115
+ reservationId,
116
+ invoiceId: invoiceResult.val.id,
117
+ subscribingUserId: subscribingUser.id,
118
+ vehicleId: vehicle.id,
119
+ businessId: payer.object === 'business' ? payer.id : undefined,
120
+ plan,
121
+ mileagePackage,
122
+ couponCode,
123
+ referralCode,
124
+ analytics,
125
+ deliveryAddresses,
126
+ deliveryDate,
127
+ asBusiness,
128
+ source,
129
+ });
130
+ return new Ok(reservation);
382
131
  };
383
- var createReservation = function(param) {
384
- var reservationId = param.reservationId, invoiceId = param.invoiceId, subscribingUserId = param.subscribingUserId, vehicleId = param.vehicleId, businessId = param.businessId, plan = param.plan, mileagePackage = param.mileagePackage, couponCode = param.couponCode, referralCode = param.referralCode, analytics = param.analytics, deliveryAddresses = param.deliveryAddresses, deliveryDate = param.deliveryDate, asBusiness = param.asBusiness, source = param.source;
385
- return _async_to_generator(function() {
386
- return _ts_generator(this, function(_state) {
387
- switch(_state.label){
388
- case 0:
389
- return [
390
- 4,
391
- prisma.subscriptionReservation.create({
392
- data: _object_spread_props(_object_spread(_object_spread_props(_object_spread({
393
- id: reservationId,
394
- invoice: {
395
- connect: {
396
- id: invoiceId
397
- }
398
- },
399
- user: {
400
- connect: {
401
- id: subscribingUserId
402
- }
403
- },
404
- vehicle: {
405
- connect: {
406
- id: vehicleId
407
- }
408
- }
409
- }, businessId ? {
410
- business: {
411
- connect: {
412
- id: businessId
413
- }
414
- }
415
- } : undefined), {
416
- plan: plan,
417
- mileagePackage: mileagePackage,
418
- couponCode: couponCode,
419
- deliveryAddresses: deliveryAddresses,
420
- deliveryDate: deliveryDate
421
- }), referralCode ? {
422
- referral: {
423
- connect: {
424
- id: referralCode
425
- }
426
- }
427
- } : undefined), {
428
- asBusiness: !!asBusiness,
429
- source: source,
430
- metadata: {
431
- analytics: analytics
432
- }
433
- })
434
- })
435
- ];
436
- case 1:
437
- return [
438
- 2,
439
- _state.sent()
440
- ];
441
- }
442
- });
443
- })();
132
+ const createReservation = async ({ reservationId, invoiceId, subscribingUserId, vehicleId, businessId, plan, mileagePackage, couponCode, referralCode, analytics, deliveryAddresses, deliveryDate, asBusiness, source, }) => {
133
+ return await prisma.subscriptionReservation.create({
134
+ data: {
135
+ id: reservationId,
136
+ invoice: {
137
+ connect: {
138
+ id: invoiceId,
139
+ },
140
+ },
141
+ user: {
142
+ connect: {
143
+ id: subscribingUserId,
144
+ },
145
+ },
146
+ vehicle: {
147
+ connect: {
148
+ id: vehicleId,
149
+ },
150
+ },
151
+ ...(businessId
152
+ ? {
153
+ business: {
154
+ connect: {
155
+ id: businessId,
156
+ },
157
+ },
158
+ }
159
+ : undefined),
160
+ plan,
161
+ mileagePackage,
162
+ couponCode: couponCode,
163
+ deliveryAddresses: deliveryAddresses,
164
+ deliveryDate: deliveryDate,
165
+ ...(referralCode
166
+ ? {
167
+ referral: {
168
+ connect: {
169
+ id: referralCode,
170
+ },
171
+ },
172
+ }
173
+ : undefined),
174
+ asBusiness: !!asBusiness,
175
+ source,
176
+ metadata: {
177
+ analytics,
178
+ },
179
+ },
180
+ });
444
181
  };
445
- var recreateReservationInvoiceAndUpdateReservation = function(previousReservation, body, vehicle, payer) {
446
- return _async_to_generator(function() {
447
- var invoiceResult, invoice, updatedReservation;
448
- return _ts_generator(this, function(_state) {
449
- switch(_state.label){
450
- case 0:
451
- return [
452
- 4,
453
- createReservationInvoice(_object_spread_props(_object_spread({}, body), {
454
- reservationId: previousReservation.id,
455
- vehicle: vehicle,
456
- payer: payer
457
- }))
458
- ];
459
- case 1:
460
- invoiceResult = _state.sent();
461
- if (!invoiceResult.ok) {
462
- return [
463
- 2,
464
- invoiceResult
465
- ];
466
- }
467
- invoice = invoiceResult.val;
468
- return [
469
- 4,
470
- prisma.subscriptionReservation.update({
471
- where: {
472
- id: previousReservation.id
473
- },
474
- data: {
475
- invoice: {
476
- connect: {
477
- id: invoice.id
478
- }
479
- }
480
- }
481
- })
482
- ];
483
- case 2:
484
- updatedReservation = _state.sent();
485
- return [
486
- 2,
487
- new Ok(updatedReservation)
488
- ];
489
- }
490
- });
491
- })();
182
+ const recreateReservationInvoiceAndUpdateReservation = async (previousReservation, body, vehicle, payer) => {
183
+ const invoiceResult = await createReservationInvoice({
184
+ ...body,
185
+ reservationId: previousReservation.id,
186
+ vehicle,
187
+ payer,
188
+ });
189
+ if (!invoiceResult.ok) {
190
+ return invoiceResult;
191
+ }
192
+ const invoice = invoiceResult.val;
193
+ const updatedReservation = await prisma.subscriptionReservation.update({
194
+ where: {
195
+ id: previousReservation.id,
196
+ },
197
+ data: {
198
+ invoice: {
199
+ connect: {
200
+ id: invoice.id,
201
+ },
202
+ },
203
+ },
204
+ });
205
+ return new Ok(updatedReservation);
492
206
  };
207
+ //# sourceMappingURL=fetch-or-create.js.map