@driveflux/api-functions 1.0.155 → 1.0.157

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 (48) hide show
  1. package/dist/auth/confirm.js +24 -24
  2. package/dist/auth/consent.js +22 -27
  3. package/dist/auth/emails.js +12 -13
  4. package/dist/auth/formatter.js +5 -5
  5. package/dist/auth/otp.js +66 -50
  6. package/dist/auth/register.js +48 -35
  7. package/dist/auth/tokens.js +58 -55
  8. package/dist/auth/verifications.js +53 -52
  9. package/dist/constants.js +0 -1
  10. package/dist/create-logger.js +1 -2
  11. package/dist/mailjet/calls/manage-contacts-in-list.js +5 -6
  12. package/dist/mailjet/calls/manage-subscription-status.js +4 -5
  13. package/dist/mailjet/calls/request-service.js +7 -6
  14. package/dist/mailjet/refresh-email-preferences.js +11 -12
  15. package/dist/mailjet/set-contact.js +11 -12
  16. package/dist/mailjet/types.js +1 -2
  17. package/dist/mailjet/utils/convert-to-array.js +8 -6
  18. package/dist/mailjet/utils/extract-email-preferences.js +14 -15
  19. package/dist/mailjet/utils/lists.js +7 -8
  20. package/dist/mailjet/utils/update-email-references.js +16 -15
  21. package/dist/notion/client.js +22 -19
  22. package/dist/notion/helpful.js +6 -9
  23. package/dist/notion/schemas/block.js +42 -48
  24. package/dist/notion/schemas/common.js +9 -14
  25. package/dist/notion/schemas/database.js +62 -60
  26. package/dist/notion/schemas/emoji.js +1 -2
  27. package/dist/notion/schemas/file.js +9 -9
  28. package/dist/notion/schemas/kb.js +5 -6
  29. package/dist/notion/schemas/page.js +72 -61
  30. package/dist/notion/schemas/parent.js +4 -5
  31. package/dist/notion/schemas/user.js +18 -19
  32. package/dist/reservation/agree.js +2 -3
  33. package/dist/reservation/checks.js +3 -4
  34. package/dist/reservation/display-vehicle.js +73 -83
  35. package/dist/reservation/ensure-user-billing-address.js +9 -11
  36. package/dist/reservation/fetch-or-create.js +49 -56
  37. package/dist/reservation/invoice.js +77 -88
  38. package/dist/reservation/payer.js +5 -6
  39. package/dist/reservation/payment-intent-sync.js +4 -6
  40. package/dist/reservation/reserve.js +3 -4
  41. package/dist/reservation/types.js +1 -2
  42. package/dist/reservation/vehicle.js +13 -16
  43. package/dist/slack.js +24 -29
  44. package/dist/validation.js +81 -85
  45. package/dist/vehicle/vehicle-pricing/constants.js +22 -19
  46. package/dist/vehicle/vehicle-pricing/index.js +28 -42
  47. package/dist/vehicle/vehicle-pricing/types.js +1 -2
  48. package/package.json +18 -18
@@ -1,73 +1,75 @@
1
1
  import { config } from '@driveflux/config/backend';
2
- import { prisma, } from '@driveflux/db';
2
+ import { prisma } from '@driveflux/db';
3
3
  import { generateId } from '@driveflux/db/id';
4
4
  import { createPricingController } from '@driveflux/db/models/vehicle';
5
- import { getFluxExcessMileage, getFluxPiceMatrix, getHostExcessMileage, getHostsMatrix, getRecommendedMotorcycleDeposit, getStartFeeMatrix, } from '../vehicle/vehicle-pricing/index.js';
6
- export const fetchDisplayVehicle = async (displayVehicle) => {
7
- return typeof displayVehicle === 'string'
8
- ? await prisma.displayVehicle.findFirst({ where: { id: displayVehicle } })
9
- : displayVehicle;
5
+ import { getFluxExcessMileage, getFluxPiceMatrix, getHostExcessMileage, getHostsMatrix, getRecommendedMotorcycleDeposit, getStartFeeMatrix } from '../vehicle/vehicle-pricing/index.js';
6
+ export const fetchDisplayVehicle = async (displayVehicle)=>{
7
+ return typeof displayVehicle === 'string' ? await prisma.displayVehicle.findFirst({
8
+ where: {
9
+ id: displayVehicle
10
+ }
11
+ }) : displayVehicle;
10
12
  };
11
- export const createVehicleFromDisplayVehicle = async (displayVehicle, selectedColor) => {
13
+ export const createVehicleFromDisplayVehicle = async (displayVehicle, selectedColor)=>{
12
14
  const dv = await fetchDisplayVehicle(displayVehicle);
13
- if (!dv || typeof dv !== 'object')
14
- return;
15
- if (!dv.details)
16
- return;
17
- const mainImage = dv.images.main.find((m) => m.variant === selectedColor)?.url;
15
+ if (!dv || typeof dv !== 'object') return;
16
+ if (!dv.details) return;
17
+ const mainImage = dv.images.main.find((m)=>m.variant === selectedColor)?.url;
18
18
  const vehicleData = {
19
19
  id: generateId('Vehicle'),
20
20
  ...transformBasicVehicleData(dv),
21
21
  images: [
22
- ...(mainImage ? [transfromSingleImage(mainImage)] : []),
23
- ...transformImages(dv.images),
22
+ ...mainImage ? [
23
+ transfromSingleImage(mainImage)
24
+ ] : [],
25
+ ...transformImages(dv.images)
24
26
  ],
25
27
  ...transformBasePrices(dv.pricing),
26
28
  pricing: transformPriceMatrix(dv.type, dv.pricing),
27
29
  details: transformDetails(dv.details, selectedColor),
28
30
  host: {
29
31
  connect: {
30
- id: dv.defaultHostId,
31
- },
32
+ id: dv.defaultHostId
33
+ }
32
34
  },
33
35
  displayVehicle: {
34
36
  connect: {
35
- id: dv.id,
36
- },
37
- },
37
+ id: dv.id
38
+ }
39
+ }
38
40
  };
39
41
  return await prisma.vehicle.create({
40
42
  data: vehicleData,
41
43
  include: {
42
- host: true,
43
- },
44
+ host: true
45
+ }
44
46
  });
45
47
  };
46
- export const transfromVehicleDisplayToVehicle = async (displayVehicle, selectedColor) => {
48
+ export const transfromVehicleDisplayToVehicle = async (displayVehicle, selectedColor)=>{
47
49
  const dv = await fetchDisplayVehicle(displayVehicle);
48
- if (!dv || typeof dv !== 'object')
49
- return;
50
- if (!dv.details)
51
- return;
52
- const mainImage = dv.images.main.find((m) => m.variant === selectedColor)?.url;
50
+ if (!dv || typeof dv !== 'object') return;
51
+ if (!dv.details) return;
52
+ const mainImage = dv.images.main.find((m)=>m.variant === selectedColor)?.url;
53
53
  return {
54
54
  id: dv.id,
55
55
  ...transformBasicVehicleData(dv),
56
56
  images: [
57
- ...(mainImage ? [transfromSingleImage(mainImage)] : []),
58
- ...transformImages(dv.images),
57
+ ...mainImage ? [
58
+ transfromSingleImage(mainImage)
59
+ ] : [],
60
+ ...transformImages(dv.images)
59
61
  ],
60
62
  ...transformBasePrices(dv.pricing),
61
63
  pricing: transformPriceMatrix(dv.type, dv.pricing),
62
64
  details: transformDetails(dv.details, selectedColor),
63
65
  host: {
64
66
  address: {
65
- state: 'Kuala Lumpur',
66
- },
67
- },
67
+ state: 'Kuala Lumpur'
68
+ }
69
+ }
68
70
  };
69
71
  };
70
- export const transformBasicVehicleData = (dv) => {
72
+ export const transformBasicVehicleData = (dv)=>{
71
73
  return {
72
74
  registrationNumber: null,
73
75
  featured: false,
@@ -85,22 +87,20 @@ export const transformBasicVehicleData = (dv) => {
85
87
  type: dv.type,
86
88
  niceName: `${dv.make} ${dv.vehicleModel} ${dv.variant} ${dv.year}`,
87
89
  niceNameShort: `${dv.make} ${dv.vehicleModel}`,
88
- appliedCoupon: dv.appliedCoupon,
90
+ appliedCoupon: dv.appliedCoupon
89
91
  };
90
92
  };
91
- export const transformImages = (images) => {
92
- const exterior = images.exterior[0]?.url
93
- ? transfromSingleImage(images.exterior[0].url, 'exterior')
94
- : null;
95
- const interior = images.interior[0]?.url
96
- ? transfromSingleImage(images.interior[0].url, 'interior')
97
- : null;
98
- const gallery = images.gallery
99
- .map((i) => (i.url ? transfromSingleImage(i.url) : null))
100
- .filter(Boolean);
101
- return [exterior, interior, ...gallery].filter(Boolean);
93
+ export const transformImages = (images)=>{
94
+ const exterior = images.exterior[0]?.url ? transfromSingleImage(images.exterior[0].url, 'exterior') : null;
95
+ const interior = images.interior[0]?.url ? transfromSingleImage(images.interior[0].url, 'interior') : null;
96
+ const gallery = images.gallery.map((i)=>i.url ? transfromSingleImage(i.url) : null).filter(Boolean);
97
+ return [
98
+ exterior,
99
+ interior,
100
+ ...gallery
101
+ ].filter(Boolean);
102
102
  };
103
- const transfromSingleImage = (imageUrl, inspectionType) => {
103
+ const transfromSingleImage = (imageUrl, inspectionType)=>{
104
104
  return {
105
105
  default: imageUrl,
106
106
  blurBase64: null,
@@ -111,20 +111,20 @@ const transfromSingleImage = (imageUrl, inspectionType) => {
111
111
  description: null,
112
112
  inspection: !!inspectionType,
113
113
  inspectionType: inspectionType || null,
114
- notActualPhoto: true,
114
+ notActualPhoto: true
115
115
  };
116
116
  };
117
- const transformBasePrices = (pricing) => {
117
+ const transformBasePrices = (pricing)=>{
118
118
  return {
119
119
  basePrice: pricing.matrix.plan36.lite,
120
120
  basePricePlan1: pricing.matrix.plan1.lite,
121
121
  basePricePlan12: pricing.matrix.plan12.lite,
122
122
  basePricePlan24: pricing.matrix.plan24.lite,
123
123
  basePricePlan36: pricing.matrix.plan36.lite,
124
- basePricePlan60: pricing.matrix.plan60.lite,
124
+ basePricePlan60: pricing.matrix.plan60.lite
125
125
  };
126
126
  };
127
- const transformPriceMatrix = (vehicleType, pricing) => {
127
+ const transformPriceMatrix = (vehicleType, pricing)=>{
128
128
  const baseline = pricing?.matrix.plan36.lite;
129
129
  const ultraTier = 'tier1';
130
130
  const fluxPriceCoefficient = 25;
@@ -137,18 +137,14 @@ const transformPriceMatrix = (vehicleType, pricing) => {
137
137
  const { availablePlans, availableMileagePackages } = getNonZeroKeys(priceMatrix);
138
138
  const pricingController = createPricingController({
139
139
  coefficient: fluxPriceCoefficient,
140
- vehicleType,
140
+ vehicleType
141
141
  });
142
142
  const startFeeMatrix = excludeServiceFeesFrom(getStartFeeMatrix(pricingController, baseline, flatPricing));
143
143
  const hostMatrix = excludeServiceFeesFrom(getHostsMatrix(pricingController, baseline, ultraTier, flatPricing));
144
144
  const hostExcessMileage = getHostExcessMileage(pricingController, baseline);
145
- const fluxPriceMatrix = pricing.keepPricingIntact
146
- ? priceMatrix
147
- : excludeServiceFeesFrom(getFluxPiceMatrix(pricingController, vehicleType, baseline, hostMatrix, ultraTier, flatPricing));
145
+ const fluxPriceMatrix = pricing.keepPricingIntact ? priceMatrix : excludeServiceFeesFrom(getFluxPiceMatrix(pricingController, vehicleType, baseline, hostMatrix, ultraTier, flatPricing));
148
146
  const fluxExcessMileage = getFluxExcessMileage(pricingController, baseline);
149
- const recommendedDeposit = pricing.refundableDeposit || vehicleType === 'motorcycle'
150
- ? getRecommendedMotorcycleDeposit(baseline)
151
- : null;
147
+ const recommendedDeposit = pricing.refundableDeposit || vehicleType === 'motorcycle' ? getRecommendedMotorcycleDeposit(baseline) : null;
152
148
  return {
153
149
  tmv,
154
150
  gfv,
@@ -167,31 +163,31 @@ const transformPriceMatrix = (vehicleType, pricing) => {
167
163
  excessMileage: fluxExcessMileage,
168
164
  originalExcessMileage: fluxExcessMileage,
169
165
  matrixComments: null,
170
- add: null,
166
+ add: null
171
167
  },
172
168
  hostTake: {
173
169
  matrix: hostMatrix,
174
170
  originalMatrix: hostMatrix,
175
171
  excessMileage: hostExcessMileage,
176
172
  originalExcessMileage: hostExcessMileage,
177
- matrixComments: null,
173
+ matrixComments: null
178
174
  },
179
175
  startFee: {
180
176
  matrix: startFeeMatrix,
181
177
  originalMatrix: startFeeMatrix,
182
- matrixComments: null,
183
- },
178
+ matrixComments: null
179
+ }
184
180
  };
185
181
  };
186
- const getNonZeroKeys = (matrix) => {
182
+ const getNonZeroKeys = (matrix)=>{
187
183
  const planKeys = new Set();
188
184
  const mileageKeys = new Set();
189
- for (const [plan, mileageMap] of Object.entries(matrix)) {
185
+ for (const [plan, mileageMap] of Object.entries(matrix)){
190
186
  const entries = Object.entries(mileageMap ?? {});
191
- const hasNonZero = entries.some(([_, value]) => (value ?? 0) > 0);
187
+ const hasNonZero = entries.some(([_, value])=>(value ?? 0) > 0);
192
188
  if (hasNonZero) {
193
189
  planKeys.add(plan);
194
- for (const [mileage, value] of entries) {
190
+ for (const [mileage, value] of entries){
195
191
  if ((value ?? 0) > 0) {
196
192
  mileageKeys.add(mileage);
197
193
  }
@@ -200,20 +196,20 @@ const getNonZeroKeys = (matrix) => {
200
196
  }
201
197
  return {
202
198
  availablePlans: Array.from(planKeys),
203
- availableMileagePackages: Array.from(mileageKeys),
199
+ availableMileagePackages: Array.from(mileageKeys)
204
200
  };
205
201
  };
206
- const _getInspection = () => {
202
+ const _getInspection = ()=>{
207
203
  return {
208
204
  exterior: 5,
209
205
  interior: 5,
210
206
  engine: 5,
211
207
  frame: 5,
212
208
  total: 5,
213
- comment: 'COMMENT HERE',
209
+ comment: 'COMMENT HERE'
214
210
  };
215
211
  };
216
- const transformDetails = (details, selectColor) => {
212
+ const transformDetails = (details, selectColor)=>{
217
213
  const color = selectColor || details.colors[0].name || '';
218
214
  return {
219
215
  numberOfSeats: details.numberOfSeats,
@@ -221,31 +217,25 @@ const transformDetails = (details, selectColor) => {
221
217
  bodyType: details.bodyType,
222
218
  transmission: details.transmission,
223
219
  engineType: details.fuelType,
224
- engineCapacity: details.fuelType === 'electric'
225
- ? details.batteryCapacity
226
- : details.engineCapacity,
220
+ engineCapacity: details.fuelType === 'electric' ? details.batteryCapacity : details.engineCapacity,
227
221
  drivetrain: details.drivetrain,
228
222
  accelerationTo100km: details.accelerationTo100km,
229
223
  fuelConsumptionLitersPer100Km: details.fuelConsumptionLitersPer100Km,
230
224
  color,
231
225
  features: details.features,
232
- condition: 'new',
226
+ condition: 'new'
233
227
  };
234
228
  };
235
- const excludeServiceFeesFrom = (originalMatrix) => {
229
+ const excludeServiceFeesFrom = (originalMatrix)=>{
236
230
  const matrix = {};
237
- for (const [planKey, planValue] of Object.entries(originalMatrix)) {
238
- if (!planValue)
239
- continue;
240
- if (!matrix[planKey])
241
- matrix[planKey] = {};
242
- for (const [mileageKey, price] of Object.entries(planValue)) {
231
+ for (const [planKey, planValue] of Object.entries(originalMatrix)){
232
+ if (!planValue) continue;
233
+ if (!matrix[planKey]) matrix[planKey] = {};
234
+ for (const [mileageKey, price] of Object.entries(planValue)){
243
235
  if (typeof price === 'number') {
244
- matrix[planKey][mileageKey] =
245
- price / (1 + config.taxRate);
236
+ matrix[planKey][mileageKey] = price / (1 + config.taxRate);
246
237
  }
247
238
  }
248
239
  }
249
240
  return matrix;
250
241
  };
251
- //# sourceMappingURL=display-vehicle.js.map
@@ -3,29 +3,27 @@ import { makeProblem, PROBLEM_INTERNAL } from '@driveflux/problem';
3
3
  import { Err, Ok } from '@driveflux/result';
4
4
  import { createScopedLogger } from '../create-logger.js';
5
5
  const log = createScopedLogger('reservation:ensure-user-billing-address');
6
- export const ensureUserBillingAddress = async (userOrBusiness, deliveryAddresses) => {
6
+ export const ensureUserBillingAddress = async (userOrBusiness, deliveryAddresses)=>{
7
7
  if (userOrBusiness.addresses?.billing) {
8
8
  return new Ok(userOrBusiness);
9
9
  }
10
10
  try {
11
11
  const fullQuery = {
12
- where: { id: userOrBusiness.id },
12
+ where: {
13
+ id: userOrBusiness.id
14
+ },
13
15
  data: {
14
16
  addresses: {
15
17
  home: deliveryAddresses.home,
16
- billing: deliveryAddresses.billing,
17
- },
18
- },
18
+ billing: deliveryAddresses.billing
19
+ }
20
+ }
19
21
  };
20
22
  // Use the delivery addresses
21
- const updatedUserOrBusiness = userOrBusiness.object === 'user'
22
- ? await prisma.user.update(fullQuery)
23
- : await prisma.business.update(fullQuery);
23
+ const updatedUserOrBusiness = userOrBusiness.object === 'user' ? await prisma.user.update(fullQuery) : await prisma.business.update(fullQuery);
24
24
  return new Ok(updatedUserOrBusiness);
25
- }
26
- catch (error) {
25
+ } catch (error) {
27
26
  log.error(error, 'Failed to ensure user billing address');
28
27
  return new Err(makeProblem(PROBLEM_INTERNAL, 'Failed to ensure user billing address'));
29
28
  }
30
29
  };
31
- //# sourceMappingURL=ensure-user-billing-address.js.map
@@ -1,12 +1,12 @@
1
- import { prisma, } from '@driveflux/db';
1
+ import { prisma } from '@driveflux/db';
2
2
  import { generateId } from '@driveflux/db/id';
3
3
  import { makeProblem, PROBLEM_UNKNOWN } from '@driveflux/problem';
4
4
  import { reportError } from '@driveflux/reporter';
5
5
  import { Err, Ok } from '@driveflux/result';
6
6
  import { slackLater } from '../slack.js';
7
- import { createReservationInvoice, updateReservationInvoiceIfNeeded, } from './invoice.js';
8
- export const fetchOrCreateReservation = async ({ vehicle, payer, body, }) => {
9
- const { subscribingUser, plan, mileagePackage, couponCode, referralCode, asBusiness, source, deliveryAddresses, deliveryDate, analytics, paymentIntentId, freeReservation, freeReservationReason, fullBooking, } = body;
7
+ import { createReservationInvoice, updateReservationInvoiceIfNeeded } from './invoice.js';
8
+ export const fetchOrCreateReservation = async ({ vehicle, payer, body })=>{
9
+ const { subscribingUser, plan, mileagePackage, couponCode, referralCode, asBusiness, source, deliveryAddresses, deliveryDate, analytics, paymentIntentId, freeReservation, freeReservationReason, fullBooking } = body;
10
10
  try {
11
11
  const previousReservation = await prisma.subscriptionReservation.findFirst({
12
12
  where: {
@@ -20,14 +20,14 @@ export const fetchOrCreateReservation = async ({ vehicle, payer, body, }) => {
20
20
  source,
21
21
  // If the subscription ID was populated, this means that this reservation was consumed into a subsription,
22
22
  // so we shouldn't re-use it
23
- subscription: null,
23
+ subscription: null
24
24
  },
25
25
  orderBy: {
26
- updatedAt: 'desc',
26
+ updatedAt: 'desc'
27
27
  },
28
28
  include: {
29
- invoice: true,
30
- },
29
+ invoice: true
30
+ }
31
31
  });
32
32
  if (previousReservation) {
33
33
  if (previousReservation.invoice.voided) {
@@ -40,7 +40,7 @@ export const fetchOrCreateReservation = async ({ vehicle, payer, body, }) => {
40
40
  'partiallyPaid',
41
41
  'partiallyRefunded',
42
42
  'refunded',
43
- 'pendingRefund',
43
+ 'pendingRefund'
44
44
  ];
45
45
  if (wrongStatuses.includes(previousReservation.invoice.status)) {
46
46
  const updatedReservation = await recreateReservationInvoiceAndUpdateReservation(previousReservation, body, vehicle, payer);
@@ -53,16 +53,16 @@ export const fetchOrCreateReservation = async ({ vehicle, payer, body, }) => {
53
53
  text: {
54
54
  type: 'plain_text',
55
55
  text: '‼️ Reservation invoice in wrong status',
56
- emoji: true,
57
- },
56
+ emoji: true
57
+ }
58
58
  },
59
59
  {
60
60
  type: 'section',
61
61
  text: {
62
62
  type: 'plain_text',
63
- 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.`,
64
- },
65
- },
63
+ 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.`
64
+ }
65
+ }
66
66
  ]);
67
67
  return updatedReservation;
68
68
  }
@@ -74,8 +74,7 @@ export const fetchOrCreateReservation = async ({ vehicle, payer, body, }) => {
74
74
  // Otherwise, we need to create a new reservation
75
75
  return new Ok(previousReservation);
76
76
  }
77
- }
78
- catch (error) {
77
+ } catch (error) {
79
78
  // We couldn't fetch the reservation, so we create a new one and just log this
80
79
  await reportError(error);
81
80
  }
@@ -96,7 +95,7 @@ export const fetchOrCreateReservation = async ({ vehicle, payer, body, }) => {
96
95
  vehicle,
97
96
  payer,
98
97
  subscribingUser,
99
- fullBooking,
98
+ fullBooking
100
99
  });
101
100
  if (invoiceResult.err) {
102
101
  return invoiceResult;
@@ -115,11 +114,10 @@ export const fetchOrCreateReservation = async ({ vehicle, payer, body, }) => {
115
114
  deliveryAddresses,
116
115
  deliveryDate,
117
116
  asBusiness,
118
- source,
117
+ source
119
118
  });
120
119
  return new Ok(reservation);
121
- }
122
- catch (e) {
120
+ } catch (e) {
123
121
  await reportError(e);
124
122
  if (typeof e === 'object' && e && 'message' in e && e.message) {
125
123
  return new Err(makeProblem(PROBLEM_UNKNOWN, e.message));
@@ -127,66 +125,62 @@ export const fetchOrCreateReservation = async ({ vehicle, payer, body, }) => {
127
125
  return new Err(makeProblem(PROBLEM_UNKNOWN, 'Unknown error'));
128
126
  }
129
127
  };
130
- const createReservation = async ({ reservationId, invoiceId, subscribingUserId, vehicleId, businessId, plan, mileagePackage, couponCode, referralCode, analytics, deliveryAddresses, deliveryDate, asBusiness, source, }) => {
128
+ const createReservation = async ({ reservationId, invoiceId, subscribingUserId, vehicleId, businessId, plan, mileagePackage, couponCode, referralCode, analytics, deliveryAddresses, deliveryDate, asBusiness, source })=>{
131
129
  return await prisma.subscriptionReservation.create({
132
130
  data: {
133
131
  id: reservationId,
134
132
  invoice: {
135
133
  connect: {
136
- id: invoiceId,
137
- },
134
+ id: invoiceId
135
+ }
138
136
  },
139
137
  user: {
140
138
  connect: {
141
- id: subscribingUserId,
142
- },
139
+ id: subscribingUserId
140
+ }
143
141
  },
144
142
  vehicle: {
145
143
  connect: {
146
- id: vehicleId,
147
- },
144
+ id: vehicleId
145
+ }
148
146
  },
149
- ...(businessId
150
- ? {
151
- business: {
152
- connect: {
153
- id: businessId,
154
- },
155
- },
147
+ ...businessId ? {
148
+ business: {
149
+ connect: {
150
+ id: businessId
151
+ }
156
152
  }
157
- : undefined),
153
+ } : undefined,
158
154
  plan,
159
155
  mileagePackage,
160
156
  couponCode: couponCode,
161
157
  deliveryAddresses: deliveryAddresses,
162
158
  deliveryDate: deliveryDate,
163
- ...(referralCode
164
- ? {
165
- referral: {
166
- connect: {
167
- id: referralCode,
168
- },
169
- },
159
+ ...referralCode ? {
160
+ referral: {
161
+ connect: {
162
+ id: referralCode
163
+ }
170
164
  }
171
- : undefined),
165
+ } : undefined,
172
166
  asBusiness: !!asBusiness,
173
167
  source,
174
168
  metadata: {
175
- analytics,
176
- },
169
+ analytics
170
+ }
177
171
  },
178
172
  include: {
179
- invoice: true,
180
- },
173
+ invoice: true
174
+ }
181
175
  });
182
176
  };
183
- const recreateReservationInvoiceAndUpdateReservation = async (previousReservation, body, vehicle, payer) => {
177
+ const recreateReservationInvoiceAndUpdateReservation = async (previousReservation, body, vehicle, payer)=>{
184
178
  const invoiceResult = await createReservationInvoice({
185
179
  ...body,
186
180
  invoiceId: generateId('Invoice'),
187
181
  reservationId: previousReservation.id,
188
182
  vehicle,
189
- payer,
183
+ payer
190
184
  });
191
185
  if (!invoiceResult.ok) {
192
186
  return invoiceResult;
@@ -194,19 +188,18 @@ const recreateReservationInvoiceAndUpdateReservation = async (previousReservatio
194
188
  const invoice = invoiceResult.val;
195
189
  const updatedReservation = await prisma.subscriptionReservation.update({
196
190
  where: {
197
- id: previousReservation.id,
191
+ id: previousReservation.id
198
192
  },
199
193
  data: {
200
194
  invoice: {
201
195
  connect: {
202
- id: invoice.id,
203
- },
204
- },
196
+ id: invoice.id
197
+ }
198
+ }
205
199
  },
206
200
  include: {
207
- invoice: true,
208
- },
201
+ invoice: true
202
+ }
209
203
  });
210
204
  return new Ok(updatedReservation);
211
205
  };
212
- //# sourceMappingURL=fetch-or-create.js.map