@driveflux/api-functions 0.0.7-next.7 → 0.0.7-next.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.
@@ -1,19 +1,19 @@
1
1
  import { type DisplayVehicle, type MileagePackage, type PlanType, type UltraTier, type Vehicle, type VehicleType } from '@driveflux/db';
2
2
  export declare const fetchDisplayVehicle: (displayVehicle: DisplayVehicle | string) => Promise<{
3
3
  object: import("@driveflux/db").DisplayVehicleObject;
4
- id: string;
5
4
  type: VehicleType;
6
- brandId: string;
7
- defaultHostId: string;
8
- vehicleSlug: string;
9
- brandSlug: string;
5
+ id: string;
6
+ createdAt: Date;
7
+ updatedAt: Date;
10
8
  make: string;
11
9
  vehicleModel: string;
12
10
  variant: string;
13
11
  year: number;
12
+ brandSlug: string;
13
+ brandId: string;
14
+ defaultHostId: string;
15
+ vehicleSlug: string;
14
16
  saveValue: number | null;
15
- createdAt: Date;
16
- updatedAt: Date;
17
17
  details: ({
18
18
  features: string[];
19
19
  range: number | null;
@@ -191,26 +191,26 @@ export declare const fetchDisplayVehicle: (displayVehicle: DisplayVehicle | stri
191
191
  export declare const createVehicleFromDisplayVehicle: (displayVehicle: DisplayVehicle | string, selectedColor?: string) => Promise<({
192
192
  host: {
193
193
  object: import("@driveflux/db").HostObject;
194
- name: string;
195
- id: string;
194
+ phoneNumber: string | null;
196
195
  type: import("@driveflux/db").HostType | null;
196
+ id: string;
197
+ metadata: PrismaJson.AnyMetadata | null;
198
+ name: string;
197
199
  createdAt: Date;
198
200
  updatedAt: Date;
199
- registrationNumber: string | null;
200
- metadata: PrismaJson.AnyMetadata | null;
201
- active: boolean;
202
- commencementDate: Date | null;
203
201
  email: string | null;
204
- phoneNumber: string | null;
202
+ race: import("@driveflux/db").Race | null;
205
203
  emergencyContactName: string | null;
206
204
  emergencyPhoneNumber: string | null;
205
+ active: boolean;
206
+ commencementDate: Date | null;
207
+ registrationNumber: string | null;
207
208
  stripeAccountId: string | null;
208
209
  isStripeConnected: boolean;
209
210
  serviceCenterIds: string[];
210
211
  enablePrepayments: boolean;
211
212
  prepaymentRatio: number | null;
212
213
  accountManagerId: string | null;
213
- race: import("@driveflux/db").Race | null;
214
214
  isInternal: boolean | null;
215
215
  address: ({
216
216
  name: string | null;
@@ -262,20 +262,24 @@ export declare const createVehicleFromDisplayVehicle: (displayVehicle: DisplayVe
262
262
  };
263
263
  } & {
264
264
  object: import("@driveflux/db").VehicleObject;
265
- id: string;
266
265
  type: VehicleType;
266
+ id: string;
267
+ metadata: PrismaJson.AnyMetadata | null;
268
+ createdAt: Date;
269
+ updatedAt: Date;
270
+ status: import("@driveflux/db").VehicleStatus;
271
+ temporary: boolean;
272
+ registrationNumber: string | null;
273
+ hostId: string;
267
274
  make: string;
268
275
  vehicleModel: string;
269
276
  variant: string;
270
277
  year: number;
271
- createdAt: Date;
272
- updatedAt: Date;
273
278
  featured: boolean;
274
279
  searchRankScore: number;
275
280
  compositeSearchScore: number;
276
281
  registrationDate: Date | null;
277
282
  mileage: number | null;
278
- registrationNumber: string | null;
279
283
  vin: string | null;
280
284
  engineNumber: string | null;
281
285
  availability: import("@driveflux/db").VehicleAvailablity | null;
@@ -286,11 +290,12 @@ export declare const createVehicleFromDisplayVehicle: (displayVehicle: DisplayVe
286
290
  basePricePlan24: number;
287
291
  basePricePlan36: number;
288
292
  basePricePlan60: number;
289
- status: import("@driveflux/db").VehicleStatus;
290
293
  listedAt: Date | null;
291
294
  delistedAt: Date | null;
292
295
  imagesNotActual: boolean;
293
296
  imagesNotActualMessage: string | null;
297
+ allowedServiceCenterIds: string[];
298
+ displayVehicleId: string | null;
294
299
  isHostConfirmed: boolean | null;
295
300
  niceName: string;
296
301
  niceNameShort: string;
@@ -301,12 +306,7 @@ export declare const createVehicleFromDisplayVehicle: (displayVehicle: DisplayVe
301
306
  featureOnLandingPage: boolean;
302
307
  lastMileageRecordedAt: Date | null;
303
308
  locationAvailability: string[];
304
- temporary: boolean;
305
309
  hotDeal: boolean | null;
306
- metadata: PrismaJson.AnyMetadata | null;
307
- hostId: string;
308
- allowedServiceCenterIds: string[];
309
- displayVehicleId: string | null;
310
310
  activeSubscriptionId: string | null;
311
311
  addresses: {
312
312
  return: {
@@ -689,20 +689,24 @@ export declare const createVehicleFromDisplayVehicle: (displayVehicle: DisplayVe
689
689
  }) | undefined>;
690
690
  export declare const transfromVehicleDisplayToVehicle: (displayVehicle: DisplayVehicle | string, selectedColor: string) => Promise<({
691
691
  object: import("@driveflux/db").VehicleObject;
692
- id: string;
693
692
  type: VehicleType;
693
+ id: string;
694
+ metadata: PrismaJson.AnyMetadata | null;
695
+ createdAt: Date;
696
+ updatedAt: Date;
697
+ status: import("@driveflux/db").VehicleStatus;
698
+ temporary: boolean;
699
+ registrationNumber: string | null;
700
+ hostId: string;
694
701
  make: string;
695
702
  vehicleModel: string;
696
703
  variant: string;
697
704
  year: number;
698
- createdAt: Date;
699
- updatedAt: Date;
700
705
  featured: boolean;
701
706
  searchRankScore: number;
702
707
  compositeSearchScore: number;
703
708
  registrationDate: Date | null;
704
709
  mileage: number | null;
705
- registrationNumber: string | null;
706
710
  vin: string | null;
707
711
  engineNumber: string | null;
708
712
  availability: import("@driveflux/db").VehicleAvailablity | null;
@@ -713,11 +717,12 @@ export declare const transfromVehicleDisplayToVehicle: (displayVehicle: DisplayV
713
717
  basePricePlan24: number;
714
718
  basePricePlan36: number;
715
719
  basePricePlan60: number;
716
- status: import("@driveflux/db").VehicleStatus;
717
720
  listedAt: Date | null;
718
721
  delistedAt: Date | null;
719
722
  imagesNotActual: boolean;
720
723
  imagesNotActualMessage: string | null;
724
+ allowedServiceCenterIds: string[];
725
+ displayVehicleId: string | null;
721
726
  isHostConfirmed: boolean | null;
722
727
  niceName: string;
723
728
  niceNameShort: string;
@@ -728,12 +733,7 @@ export declare const transfromVehicleDisplayToVehicle: (displayVehicle: DisplayV
728
733
  featureOnLandingPage: boolean;
729
734
  lastMileageRecordedAt: Date | null;
730
735
  locationAvailability: string[];
731
- temporary: boolean;
732
736
  hotDeal: boolean | null;
733
- metadata: PrismaJson.AnyMetadata | null;
734
- hostId: string;
735
- allowedServiceCenterIds: string[];
736
- displayVehicleId: string | null;
737
737
  activeSubscriptionId: string | null;
738
738
  addresses: {
739
739
  return: {
@@ -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,17 +87,17 @@ 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) => {
93
+ export const transformImages = (images)=>{
92
94
  return [
93
95
  transfromSingleImage(images.exterior[0].url, 'exterior'),
94
96
  transfromSingleImage(images.interior[0].url, 'interior'),
95
- ...images.gallery.map((i) => transfromSingleImage(i.url)),
97
+ ...images.gallery.map((i)=>transfromSingleImage(i.url))
96
98
  ];
97
99
  };
98
- const transfromSingleImage = (imageUrl, inspectionType) => {
100
+ const transfromSingleImage = (imageUrl, inspectionType)=>{
99
101
  return {
100
102
  default: imageUrl,
101
103
  blurBase64: null,
@@ -106,20 +108,20 @@ const transfromSingleImage = (imageUrl, inspectionType) => {
106
108
  description: null,
107
109
  inspection: !!inspectionType,
108
110
  inspectionType: inspectionType || null,
109
- notActualPhoto: true,
111
+ notActualPhoto: true
110
112
  };
111
113
  };
112
- const transformBasePrices = (pricing) => {
114
+ const transformBasePrices = (pricing)=>{
113
115
  return {
114
116
  basePrice: pricing.matrix.plan36.lite,
115
117
  basePricePlan1: pricing.matrix.plan1.lite,
116
118
  basePricePlan12: pricing.matrix.plan12.lite,
117
119
  basePricePlan24: pricing.matrix.plan24.lite,
118
120
  basePricePlan36: pricing.matrix.plan36.lite,
119
- basePricePlan60: pricing.matrix.plan60.lite,
121
+ basePricePlan60: pricing.matrix.plan60.lite
120
122
  };
121
123
  };
122
- const transformPriceMatrix = (vehicleType, pricing) => {
124
+ const transformPriceMatrix = (vehicleType, pricing)=>{
123
125
  const baseline = pricing?.matrix.plan36.lite;
124
126
  const ultraTier = 'tier1';
125
127
  const fluxPriceCoefficient = 25;
@@ -132,16 +134,14 @@ const transformPriceMatrix = (vehicleType, pricing) => {
132
134
  const { availablePlans, availableMileagePackages } = getNonZeroKeys(priceMatrix);
133
135
  const pricingController = createPricingController({
134
136
  coefficient: fluxPriceCoefficient,
135
- vehicleType,
137
+ vehicleType
136
138
  });
137
139
  const startFeeMatrix = excludeServiceFeesFrom(getStartFeeMatrix(pricingController, baseline, flatPricing));
138
140
  const hostMatrix = excludeServiceFeesFrom(getHostsMatrix(pricingController, baseline, ultraTier, flatPricing));
139
141
  const hostExcessMileage = getHostExcessMileage(pricingController, baseline);
140
142
  const fluxPriceMatrix = excludeServiceFeesFrom(getFluxPiceMatrix(pricingController, vehicleType, baseline, hostMatrix, ultraTier, flatPricing));
141
143
  const fluxExcessMileage = getFluxExcessMileage(pricingController, baseline);
142
- const recommendedDeposit = pricing.refundableDeposit || vehicleType === 'motorcycle'
143
- ? getRecommendedMotorcycleDeposit(baseline)
144
- : null;
144
+ const recommendedDeposit = pricing.refundableDeposit || vehicleType === 'motorcycle' ? getRecommendedMotorcycleDeposit(baseline) : null;
145
145
  return {
146
146
  tmv,
147
147
  gfv,
@@ -160,31 +160,31 @@ const transformPriceMatrix = (vehicleType, pricing) => {
160
160
  excessMileage: fluxExcessMileage,
161
161
  originalExcessMileage: fluxExcessMileage,
162
162
  matrixComments: null,
163
- add: null,
163
+ add: null
164
164
  },
165
165
  hostTake: {
166
166
  matrix: hostMatrix,
167
167
  originalMatrix: hostMatrix,
168
168
  excessMileage: hostExcessMileage,
169
169
  originalExcessMileage: hostExcessMileage,
170
- matrixComments: null,
170
+ matrixComments: null
171
171
  },
172
172
  startFee: {
173
173
  matrix: startFeeMatrix,
174
174
  originalMatrix: startFeeMatrix,
175
- matrixComments: null,
176
- },
175
+ matrixComments: null
176
+ }
177
177
  };
178
178
  };
179
- const getNonZeroKeys = (matrix) => {
179
+ const getNonZeroKeys = (matrix)=>{
180
180
  const planKeys = new Set();
181
181
  const mileageKeys = new Set();
182
- for (const [plan, mileageMap] of Object.entries(matrix)) {
182
+ for (const [plan, mileageMap] of Object.entries(matrix)){
183
183
  const entries = Object.entries(mileageMap ?? {});
184
- const hasNonZero = entries.some(([_, value]) => (value ?? 0) > 0);
184
+ const hasNonZero = entries.some(([_, value])=>(value ?? 0) > 0);
185
185
  if (hasNonZero) {
186
186
  planKeys.add(plan);
187
- for (const [mileage, value] of entries) {
187
+ for (const [mileage, value] of entries){
188
188
  if ((value ?? 0) > 0) {
189
189
  mileageKeys.add(mileage);
190
190
  }
@@ -193,20 +193,20 @@ const getNonZeroKeys = (matrix) => {
193
193
  }
194
194
  return {
195
195
  availablePlans: Array.from(planKeys),
196
- availableMileagePackages: Array.from(mileageKeys),
196
+ availableMileagePackages: Array.from(mileageKeys)
197
197
  };
198
198
  };
199
- const _getInspection = () => {
199
+ const _getInspection = ()=>{
200
200
  return {
201
201
  exterior: 5,
202
202
  interior: 5,
203
203
  engine: 5,
204
204
  frame: 5,
205
205
  total: 5,
206
- comment: 'COMMENT HERE',
206
+ comment: 'COMMENT HERE'
207
207
  };
208
208
  };
209
- const transformDetails = (details, selectColor) => {
209
+ const transformDetails = (details, selectColor)=>{
210
210
  const color = selectColor || details.colors[0].name || '';
211
211
  return {
212
212
  numberOfSeats: details.numberOfSeats,
@@ -214,31 +214,25 @@ const transformDetails = (details, selectColor) => {
214
214
  bodyType: details.bodyType,
215
215
  transmission: details.transmission,
216
216
  engineType: details.fuelType,
217
- engineCapacity: details.fuelType === 'electric'
218
- ? details.batteryCapacity
219
- : details.engineCapacity,
217
+ engineCapacity: details.fuelType === 'electric' ? details.batteryCapacity : details.engineCapacity,
220
218
  drivetrain: details.drivetrain,
221
219
  accelerationTo100km: details.accelerationTo100km,
222
220
  fuelConsumptionLitersPer100Km: details.fuelConsumptionLitersPer100Km,
223
221
  color,
224
222
  features: details.features,
225
- condition: 'new',
223
+ condition: 'new'
226
224
  };
227
225
  };
228
- const excludeServiceFeesFrom = (originalMatrix) => {
226
+ const excludeServiceFeesFrom = (originalMatrix)=>{
229
227
  const matrix = {};
230
- for (const [planKey, planValue] of Object.entries(originalMatrix)) {
231
- if (!planValue)
232
- continue;
233
- if (!matrix[planKey])
234
- matrix[planKey] = {};
235
- for (const [mileageKey, price] of Object.entries(planValue)) {
228
+ for (const [planKey, planValue] of Object.entries(originalMatrix)){
229
+ if (!planValue) continue;
230
+ if (!matrix[planKey]) matrix[planKey] = {};
231
+ for (const [mileageKey, price] of Object.entries(planValue)){
236
232
  if (typeof price === 'number') {
237
- matrix[planKey][mileageKey] =
238
- price / (1 + config.serviceRate);
233
+ matrix[planKey][mileageKey] = price / (1 + config.serviceRate);
239
234
  }
240
235
  }
241
236
  }
242
237
  return matrix;
243
238
  };
244
- //# sourceMappingURL=display-vehicle.js.map
@@ -4,7 +4,7 @@ import type { ReserveVehicleParams } from './types.js';
4
4
  type FetchOrCreateReservationParams = {
5
5
  vehicle: Pick<Vehicle, 'id' | 'make' | 'vehicleModel' | 'variant' | 'year' | 'type'>;
6
6
  payer: User | Business;
7
- body: Pick<ReserveVehicleParams, 'subscribingUser' | 'plan' | 'mileagePackage' | 'couponCode' | 'referralCode' | 'asBusiness' | 'source' | 'paymentIntentId' | 'analytics' | 'deliveryAddresses' | 'deliveryDate' | 'requestUser' | 'ipAddress' | 'freeReservation' | 'freeReservationReason'>;
7
+ body: Pick<ReserveVehicleParams, 'subscribingUser' | 'plan' | 'mileagePackage' | 'couponCode' | 'referralCode' | 'asBusiness' | 'source' | 'paymentIntentId' | 'analytics' | 'deliveryAddresses' | 'deliveryDate' | 'requestUser' | 'ipAddress' | 'freeReservation' | 'freeReservationReason' | 'invoiceId'>;
8
8
  };
9
9
  export declare const fetchOrCreateReservation: ({ vehicle, payer, body, }: FetchOrCreateReservationParams) => PromisedResult<SubscriptionReservation>;
10
10
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"fetch-or-create.d.ts","sourceRoot":"","sources":["../../src/reservation/fetch-or-create.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,QAAQ,EAGb,KAAK,uBAAuB,EAC5B,KAAK,IAAI,EACT,KAAK,OAAO,EACZ,MAAM,eAAe,CAAA;AAGtB,OAAO,EAAM,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAM3D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAEtD,KAAK,8BAA8B,GAAG;IACrC,OAAO,EAAE,IAAI,CACZ,OAAO,EACP,IAAI,GAAG,MAAM,GAAG,cAAc,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAC5D,CAAA;IACD,KAAK,EAAE,IAAI,GAAG,QAAQ,CAAA;IACtB,IAAI,EAAE,IAAI,CACT,oBAAoB,EAClB,iBAAiB,GACjB,MAAM,GACN,gBAAgB,GAChB,YAAY,GACZ,cAAc,GACd,YAAY,GACZ,QAAQ,GACR,iBAAiB,GACjB,WAAW,GACX,mBAAmB,GACnB,cAAc,GACd,aAAa,GACb,WAAW,GACX,iBAAiB,GACjB,uBAAuB,CACzB,CAAA;CACD,CAAA;AAED,eAAO,MAAM,wBAAwB,GAAU,2BAI5C,8BAA8B,KAAG,cAAc,CAAC,uBAAuB,CA+JzE,CAAA"}
1
+ {"version":3,"file":"fetch-or-create.d.ts","sourceRoot":"","sources":["../../src/reservation/fetch-or-create.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,QAAQ,EAGb,KAAK,uBAAuB,EAC5B,KAAK,IAAI,EACT,KAAK,OAAO,EACZ,MAAM,eAAe,CAAA;AAGtB,OAAO,EAAM,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAM3D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAEtD,KAAK,8BAA8B,GAAG;IACrC,OAAO,EAAE,IAAI,CACZ,OAAO,EACP,IAAI,GAAG,MAAM,GAAG,cAAc,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAC5D,CAAA;IACD,KAAK,EAAE,IAAI,GAAG,QAAQ,CAAA;IACtB,IAAI,EAAE,IAAI,CACT,oBAAoB,EAClB,iBAAiB,GACjB,MAAM,GACN,gBAAgB,GAChB,YAAY,GACZ,cAAc,GACd,YAAY,GACZ,QAAQ,GACR,iBAAiB,GACjB,WAAW,GACX,mBAAmB,GACnB,cAAc,GACd,aAAa,GACb,WAAW,GACX,iBAAiB,GACjB,uBAAuB,GACvB,WAAW,CACb,CAAA;CACD,CAAA;AAED,eAAO,MAAM,wBAAwB,GAAU,2BAI5C,8BAA8B,KAAG,cAAc,CAAC,uBAAuB,CAwKzE,CAAA"}
@@ -1,11 +1,11 @@
1
- import { prisma } from '@driveflux/db';
1
+ import { prisma, } from '@driveflux/db';
2
2
  import { generateId } from '@driveflux/db/id';
3
3
  import { reportError } from '@driveflux/reporter';
4
4
  import { Ok } from '@driveflux/result';
5
5
  import { slackLater } from '../slack.js';
6
- import { createReservationInvoice, updateReservationInvoiceIfNeeded } from './invoice.js';
7
- export const fetchOrCreateReservation = async ({ vehicle, payer, body })=>{
8
- const { subscribingUser, plan, mileagePackage, couponCode, referralCode, asBusiness, source, deliveryAddresses, deliveryDate, analytics, paymentIntentId, freeReservation, freeReservationReason } = body;
6
+ import { createReservationInvoice, updateReservationInvoiceIfNeeded, } from './invoice.js';
7
+ export const fetchOrCreateReservation = async ({ vehicle, payer, body, }) => {
8
+ const { subscribingUser, plan, mileagePackage, couponCode, referralCode, asBusiness, source, deliveryAddresses, deliveryDate, analytics, paymentIntentId, freeReservation, freeReservationReason, invoiceId, } = body;
9
9
  try {
10
10
  const previousReservation = await prisma.subscriptionReservation.findFirst({
11
11
  where: {
@@ -19,12 +19,19 @@ export const fetchOrCreateReservation = async ({ vehicle, payer, body })=>{
19
19
  source,
20
20
  // If the subscription ID was populated, this means that this reservation was consumed into a subsription,
21
21
  // so we shouldn't re-use it
22
- subscription: null
22
+ subscription: null,
23
23
  },
24
24
  orderBy: {
25
- updatedAt: 'desc'
25
+ updatedAt: 'desc',
26
26
  },
27
27
  include: {
28
+ ...(invoiceId
29
+ ? {
30
+ where: {
31
+ id: invoiceId,
32
+ },
33
+ }
34
+ : {}),
28
35
  invoice: {
29
36
  select: {
30
37
  id: true,
@@ -37,10 +44,10 @@ export const fetchOrCreateReservation = async ({ vehicle, payer, body })=>{
37
44
  status: true,
38
45
  lockedAt: true,
39
46
  unlockAt: true,
40
- locked: true
41
- }
42
- }
43
- }
47
+ locked: true,
48
+ },
49
+ },
50
+ },
44
51
  });
45
52
  if (previousReservation) {
46
53
  if (previousReservation.invoice.voided) {
@@ -53,7 +60,7 @@ export const fetchOrCreateReservation = async ({ vehicle, payer, body })=>{
53
60
  'partiallyPaid',
54
61
  'partiallyRefunded',
55
62
  'refunded',
56
- 'pendingRefund'
63
+ 'pendingRefund',
57
64
  ];
58
65
  if (wrongStatuses.includes(previousReservation.invoice.status)) {
59
66
  const updatedReservation = await recreateReservationInvoiceAndUpdateReservation(previousReservation, body, vehicle, payer);
@@ -66,16 +73,16 @@ export const fetchOrCreateReservation = async ({ vehicle, payer, body })=>{
66
73
  text: {
67
74
  type: 'plain_text',
68
75
  text: '‼️ Reservation invoice in wrong status',
69
- emoji: true
70
- }
76
+ emoji: true,
77
+ },
71
78
  },
72
79
  {
73
80
  type: 'section',
74
81
  text: {
75
82
  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
- }
83
+ 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.`,
84
+ },
85
+ },
79
86
  ]);
80
87
  return updatedReservation;
81
88
  }
@@ -87,13 +94,15 @@ export const fetchOrCreateReservation = async ({ vehicle, payer, body })=>{
87
94
  // Otherwise, we need to create a new reservation
88
95
  return new Ok(previousReservation);
89
96
  }
90
- } catch (error) {
97
+ }
98
+ catch (error) {
91
99
  // We couldn't fetch the reservation, so we create a new one and just log this
92
100
  await reportError(error);
93
101
  }
94
102
  const reservationId = generateId('SubscriptionReservation');
95
103
  // Create the reservation invoice
96
104
  const invoiceResult = await createReservationInvoice({
105
+ invoiceId,
97
106
  couponCode,
98
107
  plan,
99
108
  mileagePackage,
@@ -105,7 +114,7 @@ export const fetchOrCreateReservation = async ({ vehicle, payer, body })=>{
105
114
  analytics,
106
115
  vehicle,
107
116
  payer,
108
- subscribingUser
117
+ subscribingUser,
109
118
  });
110
119
  if (invoiceResult.err) {
111
120
  return invoiceResult;
@@ -124,62 +133,66 @@ export const fetchOrCreateReservation = async ({ vehicle, payer, body })=>{
124
133
  deliveryAddresses,
125
134
  deliveryDate,
126
135
  asBusiness,
127
- source
136
+ source,
128
137
  });
129
138
  return new Ok(reservation);
130
139
  };
131
- const createReservation = async ({ reservationId, invoiceId, subscribingUserId, vehicleId, businessId, plan, mileagePackage, couponCode, referralCode, analytics, deliveryAddresses, deliveryDate, asBusiness, source })=>{
140
+ const createReservation = async ({ reservationId, invoiceId, subscribingUserId, vehicleId, businessId, plan, mileagePackage, couponCode, referralCode, analytics, deliveryAddresses, deliveryDate, asBusiness, source, }) => {
132
141
  return await prisma.subscriptionReservation.create({
133
142
  data: {
134
143
  id: reservationId,
135
144
  invoice: {
136
145
  connect: {
137
- id: invoiceId
138
- }
146
+ id: invoiceId,
147
+ },
139
148
  },
140
149
  user: {
141
150
  connect: {
142
- id: subscribingUserId
143
- }
151
+ id: subscribingUserId,
152
+ },
144
153
  },
145
154
  vehicle: {
146
155
  connect: {
147
- id: vehicleId
148
- }
156
+ id: vehicleId,
157
+ },
149
158
  },
150
- ...businessId ? {
151
- business: {
152
- connect: {
153
- id: businessId
154
- }
159
+ ...(businessId
160
+ ? {
161
+ business: {
162
+ connect: {
163
+ id: businessId,
164
+ },
165
+ },
155
166
  }
156
- } : undefined,
167
+ : undefined),
157
168
  plan,
158
169
  mileagePackage,
159
170
  couponCode: couponCode,
160
171
  deliveryAddresses: deliveryAddresses,
161
172
  deliveryDate: deliveryDate,
162
- ...referralCode ? {
163
- referral: {
164
- connect: {
165
- id: referralCode
166
- }
173
+ ...(referralCode
174
+ ? {
175
+ referral: {
176
+ connect: {
177
+ id: referralCode,
178
+ },
179
+ },
167
180
  }
168
- } : undefined,
181
+ : undefined),
169
182
  asBusiness: !!asBusiness,
170
183
  source,
171
184
  metadata: {
172
- analytics
173
- }
174
- }
185
+ analytics,
186
+ },
187
+ },
175
188
  });
176
189
  };
177
- const recreateReservationInvoiceAndUpdateReservation = async (previousReservation, body, vehicle, payer)=>{
190
+ const recreateReservationInvoiceAndUpdateReservation = async (previousReservation, { invoiceId, ...body }, vehicle, payer) => {
178
191
  const invoiceResult = await createReservationInvoice({
179
192
  ...body,
180
193
  reservationId: previousReservation.id,
181
194
  vehicle,
182
- payer
195
+ payer,
183
196
  });
184
197
  if (!invoiceResult.ok) {
185
198
  return invoiceResult;
@@ -187,15 +200,16 @@ const recreateReservationInvoiceAndUpdateReservation = async (previousReservatio
187
200
  const invoice = invoiceResult.val;
188
201
  const updatedReservation = await prisma.subscriptionReservation.update({
189
202
  where: {
190
- id: previousReservation.id
203
+ id: previousReservation.id,
191
204
  },
192
205
  data: {
193
206
  invoice: {
194
207
  connect: {
195
- id: invoice.id
196
- }
197
- }
198
- }
208
+ id: invoice.id,
209
+ },
210
+ },
211
+ },
199
212
  });
200
213
  return new Ok(updatedReservation);
201
214
  };
215
+ //# sourceMappingURL=fetch-or-create.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetch-or-create.js","sourceRoot":"","sources":["../../src/reservation/fetch-or-create.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,MAAM,GAIN,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB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uBAAuB,CAAC,MAAM,CAAC;QACtE,KAAK,EAAE;YACN,EAAE,EAAE,mBAAmB,CAAC,EAAE;SAC1B;QACD,IAAI,EAAE;YACL,OAAO,EAAE;gBACR,OAAO,EAAE;oBACR,EAAE,EAAE,OAAO,CAAC,EAAE;iBACd;aACD;SACD;KACD,CAAC,CAAA;IACF,OAAO,IAAI,EAAE,CAAC,kBAAkB,CAAC,CAAA;AAClC,CAAC,CAAA"}
1
+ {"version":3,"file":"fetch-or-create.js","sourceRoot":"","sources":["../../src/reservation/fetch-or-create.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,MAAM,GAIN,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EAAE,EAAE,EAAuB,MAAM,mBAAmB,CAAA;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EACN,wBAAwB,EACxB,gCAAgC,GAChC,MAAM,cAAc,CAAA;AA8BrB,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,EAAE,EAC9C,OAAO,EACP,KAAK,EACL,IAAI,GAC4B,EAA2C,EAAE;IAC7E,MAAM,EACL,eAAe,EACf,IAAI,EACJ,cAAc,EACd,UAAU,EACV,YAAY,EACZ,UAAU,EACV,MAAM,EACN,iBAAiB,EACjB,YAAY,EACZ,SAAS,EACT,eAAe,EACf,eAAe,EACf,qBAAqB,EACrB,SAAS,GACT,GAAG,IAAI,CAAA;IAER,IAAI,CAAC;QACJ,MAAM,mBAAmB,GAAG,MAAM,MAAM,CAAC,uBAAuB,CAAC,SAAS,CAAC;YAC1E,KAAK,EAAE;gBACN,MAAM,EAAE,eAAe,CAAC,EAAE;gBAC1B,SAAS,EAAE,OAAO,CAAC,EAAE;gBACrB,IAAI;gBACJ,cAAc;gBACd,UAAU;gBACV,YAAY;gBACZ,UAAU,EAA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,CAAE;oBACD,QAAQ,EAAE;wBACT,OAAO,EAAE;4BACR,EAAE,EAAE,YAAY;yBAChB;qBACD;iBACS;gBACZ,CAAC,CAAC,SAAS,CAAC;YACb,UAAU,EAAE,CAAC,CAAC,UAAU;YACxB,MAAM;YACN,QAAQ,EAAE;gBACT,SAAS;aACT;SACD;KACD,CAAC,CAAA;AACH,CAAC,CAAA;AAED,MAAM,8CAA8C,GAAG,KAAK,EAC3D,mBAA4C,EAC5C,EAAE,SAAS,EAAE,GAAG,IAAI,EAA0C,EAC9D,OAGC,EACD,KAAsB,EACoB,EAAE;IAC5C,MAAM,aAAa,GAAG,MAAM,wBAAwB,CAAC;QACpD,GAAG,IAAI;QACP,aAAa,EAAE,mBAAmB,CAAC,EAAE;QACrC,OAAO;QACP,KAAK;KACL,CAAC,CAAA;IACF,IAAI,CAAC,aAAa,CAAC,EAAE,EAAE,CAAC;QACvB,OAAO,aAAa,CAAA;IACrB,CAAC;IACD,MAAM,OAAO,GAAG,aAAa,CAAC,GAAG,CAAA;IACjC,MAAM,kBAAkB,GAAG,MAAM,MAAM,CAAC,uBAAuB,CAAC,MAAM,CAAC;QACtE,KAAK,EAAE;YACN,EAAE,EAAE,mBAAmB,CAAC,EAAE;SAC1B;QACD,IAAI,EAAE;YACL,OAAO,EAAE;gBACR,OAAO,EAAE;oBACR,EAAE,EAAE,OAAO,CAAC,EAAE;iBACd;aACD;SACD;KACD,CAAC,CAAA;IACF,OAAO,IAAI,EAAE,CAAC,kBAAkB,CAAC,CAAA;AAClC,CAAC,CAAA"}
@@ -1,12 +1,12 @@
1
1
  import { type Business, type Invoice, type User, type Vehicle } from '@driveflux/db';
2
2
  import { type PromisedResult } from '@driveflux/result';
3
3
  import type { ReserveVehicleParams } from './types.js';
4
- type CreateReservationInvoiceParams = Pick<ReserveVehicleParams, 'couponCode' | 'plan' | 'mileagePackage' | 'referralCode' | 'paymentIntentId' | 'freeReservation' | 'freeReservationReason' | 'analytics' | 'subscribingUser'> & {
4
+ type CreateReservationInvoiceParams = Pick<ReserveVehicleParams, 'couponCode' | 'plan' | 'mileagePackage' | 'referralCode' | 'paymentIntentId' | 'freeReservation' | 'freeReservationReason' | 'analytics' | 'subscribingUser' | 'invoiceId'> & {
5
5
  reservationId?: string;
6
6
  vehicle: Pick<Vehicle, 'id' | 'make' | 'vehicleModel' | 'variant' | 'year' | 'type'>;
7
7
  payer: User | Business;
8
8
  };
9
9
  export declare const updateReservationInvoiceIfNeeded: (oldReservationInvoice: Pick<Invoice, "id" | "couponCode" | "stripePaymentIntentId" | "lines" | "payerId" | "discountIds" | "lockedAt">, newParams: Pick<CreateReservationInvoiceParams, "couponCode" | "paymentIntentId">) => PromisedResult<Invoice>;
10
- export declare const createReservationInvoice: ({ couponCode, plan, mileagePackage, referralCode, reservationId, paymentIntentId, freeReservation, freeReservationReason, analytics, vehicle, payer, subscribingUser, }: CreateReservationInvoiceParams) => PromisedResult<Invoice>;
10
+ export declare const createReservationInvoice: ({ invoiceId, couponCode, plan, mileagePackage, referralCode, reservationId, paymentIntentId, freeReservation, freeReservationReason, analytics, vehicle, payer, subscribingUser, }: CreateReservationInvoiceParams) => PromisedResult<Invoice>;
11
11
  export {};
12
12
  //# sourceMappingURL=invoice.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"invoice.d.ts","sourceRoot":"","sources":["../../src/reservation/invoice.ts"],"names":[],"mappings":"AAMA,OAAO,EACN,KAAK,QAAQ,EACb,KAAK,OAAO,EAEZ,KAAK,IAAI,EACT,KAAK,OAAO,EACZ,MAAM,eAAe,CAAA;AAQtB,OAAO,EAAM,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAI3D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAEtD,KAAK,8BAA8B,GAAG,IAAI,CACzC,oBAAoB,EAClB,YAAY,GACZ,MAAM,GACN,gBAAgB,GAChB,cAAc,GACd,iBAAiB,GACjB,iBAAiB,GACjB,uBAAuB,GACvB,WA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E,IAAI,GAAG,QAAQ,CAAA;CACtB,CAAA;AAED,eAAO,MAAM,gCAAgC,GAC5C,uBAAuB,IAAI,CAC1B,OAAO,EACL,IAAI,GACJ,YAAY,GACZ,uBAAuB,GACvB,OAAO,GACP,SAAS,GACT,aAAa,GACb,UAAU,CACZ,EACD,WAAW,IAAI,CACd,8BAA8B,EAC9B,YAAY,GAAG,iBAAiB,CAChC,KACC,cAAc,CAAC,OAAO,CAuGxB,CAAA;AAED,eAAO,MAAM,wBAAwB,GAAU,oLAc5C,8BAA8B,KAAG,cAAc,CAAC,OAAO,CA6GzD,CAAA"}
@@ -1,6 +1,6 @@
1
1
  import { config } from '@driveflux/config/backend';
2
2
  import { loadCoupon, PROBLEM_APPLICABLE_NOT_FOUND } from '@driveflux/coupon';
3
- import { prisma } from '@driveflux/db';
3
+ import { prisma, } from '@driveflux/db';
4
4
  import { generateId } from '@driveflux/db/id';
5
5
  import { EMPTY_BILLING_ADDRESS } from '@driveflux/db/models/other';
6
6
  import { PURPOSE_RESERVATION } from '@driveflux/db/models/subscription';
@@ -12,16 +12,16 @@ import { Ok } from '@driveflux/result';
12
12
  import { format } from '@driveflux/time';
13
13
  import { isAfter } from 'date-fns/isAfter';
14
14
  import { subMinutes } from 'date-fns/subMinutes';
15
- export const updateReservationInvoiceIfNeeded = async (oldReservationInvoice, newParams)=>{
16
- console.log('UPDATING INVOICE IF NEEDED');
15
+ export const updateReservationInvoiceIfNeeded = async (oldReservationInvoice, newParams) => {
17
16
  const couponIsDifferent = oldReservationInvoice.couponCode !== newParams.couponCode;
18
- if (!couponIsDifferent && oldReservationInvoice.stripePaymentIntentId === newParams.paymentIntentId) {
17
+ if (!couponIsDifferent &&
18
+ oldReservationInvoice.stripePaymentIntentId === newParams.paymentIntentId) {
19
19
  return new Ok(oldReservationInvoice);
20
20
  }
21
21
  // If the coupon or payment intent are differnt we should update the invoice
22
22
  let update = {
23
23
  stripePaymentIntentId: newParams.paymentIntentId,
24
- couponCode: newParams.couponCode
24
+ couponCode: newParams.couponCode,
25
25
  };
26
26
  // If the coupon is different, we need to apply the coupon to the invoice
27
27
  if (couponIsDifferent) {
@@ -29,57 +29,63 @@ export const updateReservationInvoiceIfNeeded = async (oldReservationInvoice, ne
29
29
  const result = await coupons.applyCouponToUnsavedInvoice(newParams.couponCode, oldReservationInvoice);
30
30
  if (result.ok) {
31
31
  const { discounts, ...rest } = result.val;
32
- const toDisconnect = discounts ? oldReservationInvoice.discountIds?.filter((id)=>!discounts.connect?.some((d)=>d.id === id)) : undefined;
33
- const disconnectClauses = toDisconnect?.length ? {
34
- disconnect: toDisconnect.map((id)=>({
35
- id
36
- }))
37
- } : undefined;
32
+ const toDisconnect = discounts
33
+ ? oldReservationInvoice.discountIds?.filter((id) => !discounts.connect?.some((d) => d.id === id))
34
+ : undefined;
35
+ const disconnectClauses = toDisconnect?.length
36
+ ? {
37
+ disconnect: toDisconnect.map((id) => ({ id })),
38
+ }
39
+ : undefined;
38
40
  update = {
39
41
  ...update,
40
42
  ...rest,
41
- ...discounts || disconnectClauses ? {
42
- discounts: {
43
- ...discounts || {},
44
- ...disconnectClauses || {}
43
+ ...(discounts || disconnectClauses
44
+ ? {
45
+ discounts: {
46
+ ...(discounts || {}),
47
+ ...(disconnectClauses || {}),
48
+ },
45
49
  }
46
- } : {},
50
+ : {}),
47
51
  metadata: {
48
52
  ...update.metadata,
49
- couponCode: newParams.couponCode
53
+ couponCode: newParams.couponCode,
50
54
  },
51
55
  providerMetadata: {
52
56
  ...update.providerMetadata,
53
- couponCode: newParams.couponCode
54
- }
57
+ couponCode: newParams.couponCode,
58
+ },
55
59
  };
56
60
  }
57
61
  if (result.err && result.val.code !== PROBLEM_APPLICABLE_NOT_FOUND) {
58
62
  return result;
59
63
  }
60
- } else if (oldReservationInvoice.discountIds.length) {
64
+ }
65
+ else if (oldReservationInvoice.discountIds.length) {
61
66
  // No discounts, so we disconnect all of them
62
67
  update = {
63
68
  discounts: {
64
- disconnect: oldReservationInvoice.discountIds.map((id)=>({
65
- id
66
- }))
67
- }
69
+ disconnect: oldReservationInvoice.discountIds.map((id) => ({
70
+ id,
71
+ })),
72
+ },
68
73
  };
69
74
  }
70
75
  }
71
76
  let updated = await wrapInResult(biller.updateInvoice(oldReservationInvoice.id, update));
72
- console.log('Updating invoice result', updated);
73
77
  // If the invoice was locked due to pending status and we're more than 1 minute old, we unlock it
74
78
  if (updated.err && updated.val.code === 'invoice_pending') {
75
- if (oldReservationInvoice.lockedAt && isAfter(oldReservationInvoice.lockedAt, subMinutes(new Date(), 1)) || !oldReservationInvoice.lockedAt) {
79
+ if ((oldReservationInvoice.lockedAt &&
80
+ isAfter(oldReservationInvoice.lockedAt, subMinutes(new Date(), 1))) ||
81
+ !oldReservationInvoice.lockedAt) {
76
82
  updated = await wrapInResult(biller.updateInvoice(oldReservationInvoice.id, {
77
83
  ...update,
78
84
  locked: false,
79
85
  lockedAt: null,
80
86
  lockReason: null,
81
87
  unlockAt: null,
82
- status: 'draft'
88
+ status: 'draft',
83
89
  }));
84
90
  }
85
91
  }
@@ -88,10 +94,11 @@ export const updateReservationInvoiceIfNeeded = async (oldReservationInvoice, ne
88
94
  }
89
95
  return new Ok(updated.val);
90
96
  };
91
- export const createReservationInvoice = async ({ couponCode, plan, mileagePackage, referralCode, reservationId, paymentIntentId, freeReservation, freeReservationReason, analytics, vehicle, payer, subscribingUser })=>{
97
+ export const createReservationInvoice = async ({ invoiceId, couponCode, plan, mileagePackage, referralCode, reservationId, paymentIntentId, freeReservation, freeReservationReason, analytics, vehicle, payer, subscribingUser, }) => {
92
98
  if (freeReservation) {
93
99
  // It's a free reservation, so we don't need to add a coupon code
94
100
  return await wrapInResult(biller.createInvoice(getInvoiceCreateDetails({
101
+ invoiceId,
95
102
  payer,
96
103
  vehicle,
97
104
  plan,
@@ -100,17 +107,21 @@ export const createReservationInvoice = async ({ couponCode, plan, mileagePackag
100
107
  freeReservation,
101
108
  freeReservationReason,
102
109
  analytics,
103
- reservationId
110
+ reservationId,
104
111
  })));
105
112
  }
106
113
  let finalCouponCode = couponCode;
107
114
  // If we don't have a reservation coupon ID, we apply the referral discount if any
108
- const referral = referralCode && await prisma.referral.findUnique({
109
- where: {
110
- id: referralCode
111
- }
112
- });
113
- if (!finalCouponCode && referral && referral.discountToReceiverCouponId && referral.discountToReceiverCouponApplicationName === 'reservationFee') {
115
+ const referral = referralCode &&
116
+ (await prisma.referral.findUnique({
117
+ where: {
118
+ id: referralCode,
119
+ },
120
+ }));
121
+ if (!finalCouponCode &&
122
+ referral &&
123
+ referral.discountToReceiverCouponId &&
124
+ referral.discountToReceiverCouponApplicationName === 'reservationFee') {
114
125
  const referralCoupon = await loadCoupon(referral.discountToReceiverCouponId);
115
126
  if (referralCoupon) {
116
127
  finalCouponCode = referralCoupon.code;
@@ -120,6 +131,7 @@ export const createReservationInvoice = async ({ couponCode, plan, mileagePackag
120
131
  // We leave adding the coupon code applyCouponToUnsavedInvoice()
121
132
  let invoiceCreateDetails = {
122
133
  ...getInvoiceCreateDetails({
134
+ invoiceId,
123
135
  payer,
124
136
  vehicle,
125
137
  plan,
@@ -128,15 +140,15 @@ export const createReservationInvoice = async ({ couponCode, plan, mileagePackag
128
140
  freeReservation,
129
141
  freeReservationReason,
130
142
  analytics,
131
- reservationId
143
+ reservationId,
132
144
  }),
133
145
  lines: [
134
146
  {
135
147
  amount: reservationAmount,
136
148
  description: `Reservation fee for ${vehicleName(vehicle)}`,
137
- chargingFor: 'reservationFee'
138
- }
139
- ]
149
+ chargingFor: 'reservationFee',
150
+ },
151
+ ],
140
152
  };
141
153
  if (finalCouponCode) {
142
154
  const withCoupon = await coupons.applyCouponToUnsavedInvoice(finalCouponCode, invoiceCreateDetails, 'reservationFee', {
@@ -146,9 +158,10 @@ export const createReservationInvoice = async ({ couponCode, plan, mileagePackag
146
158
  vehicleMake: vehicle.make,
147
159
  userId: subscribingUser.id,
148
160
  businessId: payer.object === 'business' ? payer.id : undefined,
149
- vehicleType: vehicle.type
161
+ vehicleType: vehicle.type,
150
162
  });
151
- if (withCoupon.err && withCoupon.val.code !== PROBLEM_APPLICABLE_NOT_FOUND) {
163
+ if (withCoupon.err &&
164
+ withCoupon.val.code !== PROBLEM_APPLICABLE_NOT_FOUND) {
152
165
  return withCoupon;
153
166
  }
154
167
  if (withCoupon.ok) {
@@ -156,18 +169,18 @@ export const createReservationInvoice = async ({ couponCode, plan, mileagePackag
156
169
  ...withCoupon.val,
157
170
  metadata: {
158
171
  ...withCoupon.val.metadata,
159
- couponCode: finalCouponCode
172
+ couponCode: finalCouponCode,
160
173
  },
161
174
  providerMetadata: {
162
175
  ...withCoupon.val.providerMetadata,
163
- couponCode: finalCouponCode
164
- }
176
+ couponCode: finalCouponCode,
177
+ },
165
178
  };
166
179
  }
167
180
  }
168
181
  return await wrapInResult(biller.createInvoice(invoiceCreateDetails));
169
182
  };
170
- const getInvoiceCreateDetails = ({ invoiceId, payer, date, reservationDiscountId, vehicle, plan, mileagePackage, couponCode, paymentIntentId, freeReservation, freeReservationReason, analytics, reservationId })=>{
183
+ const getInvoiceCreateDetails = ({ invoiceId, payer, date, reservationDiscountId, vehicle, plan, mileagePackage, couponCode, paymentIntentId, freeReservation, freeReservationReason, analytics, reservationId, }) => {
171
184
  return {
172
185
  id: invoiceId || generateId('Invoice'),
173
186
  taxPercentage: 0,
@@ -183,13 +196,15 @@ const getInvoiceCreateDetails = ({ invoiceId, payer, date, reservationDiscountId
183
196
  description: 'Reservation fee for a FLUX subscription',
184
197
  footer: `Invoice for a FLUX subscription reservation. Due by ${format(date ?? new Date())}`,
185
198
  invoiceUrl: `${config.appUrl}/invoice-preview/${invoiceId}`,
186
- ...reservationDiscountId ? {
187
- discounts: {
188
- connect: {
189
- id: reservationDiscountId
190
- }
199
+ ...(reservationDiscountId
200
+ ? {
201
+ discounts: {
202
+ connect: {
203
+ id: reservationDiscountId,
204
+ },
205
+ },
191
206
  }
192
- } : {},
207
+ : {}),
193
208
  lines: [],
194
209
  subscriptionDetails: {
195
210
  vehicleId: vehicle.id,
@@ -198,7 +213,7 @@ const getInvoiceCreateDetails = ({ invoiceId, payer, date, reservationDiscountId
198
213
  variant: vehicle.variant,
199
214
  year: vehicle.year,
200
215
  plan: plan,
201
- mileagePackage: mileagePackage
216
+ mileagePackage: mileagePackage,
202
217
  },
203
218
  stripePaymentIntentId: paymentIntentId,
204
219
  providerMetadata: {
@@ -206,18 +221,14 @@ const getInvoiceCreateDetails = ({ invoiceId, payer, date, reservationDiscountId
206
221
  mileagePackage,
207
222
  vehicleId: vehicle.id,
208
223
  vehicleName: vehicleName(vehicle),
209
- ...reservationId ? {
210
- reservationId
211
- } : {},
212
- ...couponCode ? {
213
- couponCode
214
- } : {}
224
+ ...(reservationId ? { reservationId } : {}),
225
+ ...(couponCode ? { couponCode } : {}),
215
226
  },
216
227
  autoRetry: {
217
228
  enabled: false,
218
229
  interval: 0,
219
230
  maxAttempts: 0,
220
- attempts: 0
231
+ attempts: 0,
221
232
  },
222
233
  metadata: {
223
234
  purpose: PURPOSE_RESERVATION,
@@ -226,10 +237,11 @@ const getInvoiceCreateDetails = ({ invoiceId, payer, date, reservationDiscountId
226
237
  plan,
227
238
  mileagePackage,
228
239
  couponCode,
229
- ...freeReservation && freeReservationReason ? {
230
- freeReservationReason
231
- } : {},
232
- analytics
233
- }
240
+ ...(freeReservation && freeReservationReason
241
+ ? { freeReservationReason }
242
+ : {}),
243
+ analytics,
244
+ },
234
245
  };
235
246
  };
247
+ //# sourceMappingURL=invoice.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"invoice.js","sourceRoot":"","sources":["../../src/reservation/invoice.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAA;AAC5E,OAAO,EAGN,MAAM,GAGN,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,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;YACb,WAAW,EAAE,WAAW,CAAC,OAAO,CAAC;YACjC,IAAI;YACJ,cAAc;YACd,UAAU;YACV,GAAG,CAAC,eAAe,IAAI,qBAAqB;gBAC3C,CAAC,CAAC,EAAE,qBAAqB,EAAE;gBAC3B,CAAC,CAAC,EAAE,CAAC;YACN,SAAS;SACT;KAC+B,CAAA;AAClC,CAAC,CAAA"}
@@ -1,6 +1,7 @@
1
1
  import type { MileagePackage, PlanType, ReservationSource, User } from '@driveflux/db';
2
2
  import type { Address } from '@driveflux/db/types/helpers';
3
3
  export type ReserveVehicleParams = {
4
+ invoiceId?: string;
4
5
  plan: PlanType;
5
6
  mileagePackage: MileagePackage;
6
7
  asBusiness?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/reservation/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,cAAc,EACd,QAAQ,EACR,iBAAiB,EACjB,IAAI,EACJ,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAA;AAE1D,MAAM,MAAM,oBAAoB,GAAG;IAClC,IAAI,EAAE,QAAQ,CAAA;IACd,cAAc,EAAE,cAAc,CAAA;IAC9B,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,SAAS,CAAC,EAAE;QACX,UAAU,CAAC,EAAE,MAAM,CAAA;QACnB,WAAW,CAAC,EAAE,MAAM,CAAA;KACpB,CAAA;IACD,iBAAiB,CAAC,EAAE;QACnB,IAAI,EAAE,OAAO,CAAA;QACb,OAAO,EAAE,OAAO,CAAA;KAChB,CAAA;IACD,YAAY,CAAC,EAAE,IAAI,CAAA;IACnB,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC7B,eAAe,CAAC,EAAE,OAAO,CAA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ACvB,CAAA"}
@@ -1 +1,2 @@
1
- export { };
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@driveflux/api-functions",
3
- "version": "0.0.7-next.7",
3
+ "version": "0.0.7-next.8",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./notion": {
@@ -74,21 +74,21 @@
74
74
  "dependencies": {
75
75
  "@casl/ability": "^6.7.3",
76
76
  "@driveflux/auth": "3.0.0-next.5",
77
- "@driveflux/billing": "7.0.0-develop.33",
77
+ "@driveflux/billing": "7.0.0-develop.35",
78
78
  "@driveflux/config": "2.1.0-next.1",
79
- "@driveflux/coupon": "8.0.0-develop.39",
80
- "@driveflux/db": "3.0.0-develop.58",
81
- "@driveflux/email": "6.0.0-develop.39",
82
- "@driveflux/email-templates": "0.0.2-develop.41",
83
- "@driveflux/engine": "0.1.2-develop.65",
79
+ "@driveflux/coupon": "8.0.0-develop.43",
80
+ "@driveflux/db": "3.0.0-develop.60",
81
+ "@driveflux/email": "6.0.0-develop.41",
82
+ "@driveflux/email-templates": "0.0.2-develop.44",
83
+ "@driveflux/engine": "0.1.2-develop.70",
84
84
  "@driveflux/fetch": "7.0.3",
85
85
  "@driveflux/format-money": "6.0.2",
86
86
  "@driveflux/problem": "5.0.3",
87
87
  "@driveflux/reporter": "6.0.4-next.2",
88
88
  "@driveflux/result": "5.0.3",
89
- "@driveflux/scheduler": "7.0.0-develop.39",
89
+ "@driveflux/scheduler": "7.0.0-develop.42",
90
90
  "@driveflux/singleton": "2.0.2",
91
- "@driveflux/subscription": "8.0.0-develop.28",
91
+ "@driveflux/subscription": "8.0.0-develop.29",
92
92
  "@driveflux/time": "5.0.2",
93
93
  "@driveflux/utils": "5.0.2",
94
94
  "@notionhq/client": "^4.0.2",