@driveflux/api-functions 0.0.7-next.27 → 0.0.7-next.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/confirm.js +24 -29
- package/dist/auth/emails.js +12 -13
- package/dist/auth/formatter.js +5 -5
- package/dist/auth/otp.js +66 -50
- package/dist/auth/register.js +42 -34
- package/dist/auth/tokens.js +58 -55
- package/dist/auth/verifications.js +53 -52
- package/dist/constants.js +0 -1
- package/dist/mailjet/calls/manage-contacts-in-list.js +5 -6
- package/dist/mailjet/calls/manage-subscription-status.js +4 -5
- package/dist/mailjet/calls/request-service.js +7 -6
- package/dist/mailjet/refresh-email-preferences.js +11 -12
- package/dist/mailjet/set-contact.js +11 -12
- package/dist/mailjet/types.js +1 -2
- package/dist/mailjet/utils/convert-to-array.js +8 -6
- package/dist/mailjet/utils/extract-email-preferences.js +14 -15
- package/dist/mailjet/utils/lists.js +7 -8
- package/dist/mailjet/utils/update-email-references.js +16 -15
- package/dist/notion/client.js +22 -19
- package/dist/notion/helpful.js +6 -9
- package/dist/notion/schemas/block.js +42 -48
- package/dist/notion/schemas/common.js +9 -14
- package/dist/notion/schemas/database.js +62 -60
- package/dist/notion/schemas/emoji.js +1 -2
- package/dist/notion/schemas/file.js +9 -9
- package/dist/notion/schemas/kb.js +5 -6
- package/dist/notion/schemas/page.js +72 -61
- package/dist/notion/schemas/parent.js +4 -5
- package/dist/notion/schemas/user.js +18 -19
- package/dist/reservation/agree.js +6 -7
- package/dist/reservation/checks.js +3 -4
- package/dist/reservation/display-vehicle.js +65 -71
- package/dist/reservation/fetch-or-create.js +48 -54
- package/dist/reservation/invoice.js +62 -74
- package/dist/reservation/payer.js +5 -6
- package/dist/reservation/reserve.js +3 -4
- package/dist/reservation/types.js +1 -2
- package/dist/reservation/vehicle.js +13 -16
- package/dist/slack.js +24 -29
- package/dist/validation.js +77 -79
- package/dist/vehicle/vehicle-pricing/constants.js +22 -19
- package/dist/vehicle/vehicle-pricing/index.js +28 -42
- package/dist/vehicle/vehicle-pricing/types.js +1 -2
- package/package.json +8 -8
|
@@ -1,73 +1,75 @@
|
|
|
1
1
|
import { config } from '@driveflux/config/backend';
|
|
2
|
-
import { prisma
|
|
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
|
|
6
|
-
export const fetchDisplayVehicle = async (displayVehicle)
|
|
7
|
-
return typeof displayVehicle === 'string'
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
15
|
-
|
|
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
|
-
...
|
|
23
|
-
|
|
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
|
-
|
|
50
|
-
|
|
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
|
-
...
|
|
58
|
-
|
|
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)
|
|
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])
|
|
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
|
-
|
|
233
|
-
|
|
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
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { prisma
|
|
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
|
|
7
|
-
export const fetchOrCreateReservation = async ({ vehicle, payer, body
|
|
8
|
-
const { subscribingUser, plan, mileagePackage, couponCode, referralCode, asBusiness, source, deliveryAddresses, deliveryDate, analytics, paymentIntentId, freeReservation, freeReservationReason
|
|
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;
|
|
9
9
|
try {
|
|
10
10
|
const previousReservation = await prisma.subscriptionReservation.findFirst({
|
|
11
11
|
where: {
|
|
@@ -19,10 +19,10 @@ 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
28
|
invoice: {
|
|
@@ -37,10 +37,10 @@ export const fetchOrCreateReservation = async ({ vehicle, payer, body, }) => {
|
|
|
37
37
|
status: true,
|
|
38
38
|
lockedAt: true,
|
|
39
39
|
unlockAt: true,
|
|
40
|
-
locked: true
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
40
|
+
locked: true
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
44
|
});
|
|
45
45
|
if (previousReservation) {
|
|
46
46
|
if (previousReservation.invoice.voided) {
|
|
@@ -53,7 +53,7 @@ export const fetchOrCreateReservation = async ({ vehicle, payer, body, }) => {
|
|
|
53
53
|
'partiallyPaid',
|
|
54
54
|
'partiallyRefunded',
|
|
55
55
|
'refunded',
|
|
56
|
-
'pendingRefund'
|
|
56
|
+
'pendingRefund'
|
|
57
57
|
];
|
|
58
58
|
if (wrongStatuses.includes(previousReservation.invoice.status)) {
|
|
59
59
|
const updatedReservation = await recreateReservationInvoiceAndUpdateReservation(previousReservation, body, vehicle, payer);
|
|
@@ -66,16 +66,16 @@ export const fetchOrCreateReservation = async ({ vehicle, payer, body, }) => {
|
|
|
66
66
|
text: {
|
|
67
67
|
type: 'plain_text',
|
|
68
68
|
text: '‼️ Reservation invoice in wrong status',
|
|
69
|
-
emoji: true
|
|
70
|
-
}
|
|
69
|
+
emoji: true
|
|
70
|
+
}
|
|
71
71
|
},
|
|
72
72
|
{
|
|
73
73
|
type: 'section',
|
|
74
74
|
text: {
|
|
75
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
|
-
}
|
|
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
79
|
]);
|
|
80
80
|
return updatedReservation;
|
|
81
81
|
}
|
|
@@ -87,8 +87,7 @@ export const fetchOrCreateReservation = async ({ vehicle, payer, body, }) => {
|
|
|
87
87
|
// Otherwise, we need to create a new reservation
|
|
88
88
|
return new Ok(previousReservation);
|
|
89
89
|
}
|
|
90
|
-
}
|
|
91
|
-
catch (error) {
|
|
90
|
+
} catch (error) {
|
|
92
91
|
// We couldn't fetch the reservation, so we create a new one and just log this
|
|
93
92
|
await reportError(error);
|
|
94
93
|
}
|
|
@@ -107,7 +106,7 @@ export const fetchOrCreateReservation = async ({ vehicle, payer, body, }) => {
|
|
|
107
106
|
analytics,
|
|
108
107
|
vehicle,
|
|
109
108
|
payer,
|
|
110
|
-
subscribingUser
|
|
109
|
+
subscribingUser
|
|
111
110
|
});
|
|
112
111
|
if (invoiceResult.err) {
|
|
113
112
|
return invoiceResult;
|
|
@@ -126,67 +125,63 @@ export const fetchOrCreateReservation = async ({ vehicle, payer, body, }) => {
|
|
|
126
125
|
deliveryAddresses,
|
|
127
126
|
deliveryDate,
|
|
128
127
|
asBusiness,
|
|
129
|
-
source
|
|
128
|
+
source
|
|
130
129
|
});
|
|
131
130
|
return new Ok(reservation);
|
|
132
131
|
};
|
|
133
|
-
const createReservation = async ({ reservationId, invoiceId, subscribingUserId, vehicleId, businessId, plan, mileagePackage, couponCode, referralCode, analytics, deliveryAddresses, deliveryDate, asBusiness, source
|
|
132
|
+
const createReservation = async ({ reservationId, invoiceId, subscribingUserId, vehicleId, businessId, plan, mileagePackage, couponCode, referralCode, analytics, deliveryAddresses, deliveryDate, asBusiness, source })=>{
|
|
134
133
|
return await prisma.subscriptionReservation.create({
|
|
135
134
|
data: {
|
|
136
135
|
id: reservationId,
|
|
137
136
|
invoice: {
|
|
138
137
|
connect: {
|
|
139
|
-
id: invoiceId
|
|
140
|
-
}
|
|
138
|
+
id: invoiceId
|
|
139
|
+
}
|
|
141
140
|
},
|
|
142
141
|
user: {
|
|
143
142
|
connect: {
|
|
144
|
-
id: subscribingUserId
|
|
145
|
-
}
|
|
143
|
+
id: subscribingUserId
|
|
144
|
+
}
|
|
146
145
|
},
|
|
147
146
|
vehicle: {
|
|
148
147
|
connect: {
|
|
149
|
-
id: vehicleId
|
|
150
|
-
}
|
|
148
|
+
id: vehicleId
|
|
149
|
+
}
|
|
151
150
|
},
|
|
152
|
-
...
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
},
|
|
158
|
-
},
|
|
151
|
+
...businessId ? {
|
|
152
|
+
business: {
|
|
153
|
+
connect: {
|
|
154
|
+
id: businessId
|
|
155
|
+
}
|
|
159
156
|
}
|
|
160
|
-
|
|
157
|
+
} : undefined,
|
|
161
158
|
plan,
|
|
162
159
|
mileagePackage,
|
|
163
160
|
couponCode: couponCode,
|
|
164
161
|
deliveryAddresses: deliveryAddresses,
|
|
165
162
|
deliveryDate: deliveryDate,
|
|
166
|
-
...
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
},
|
|
172
|
-
},
|
|
163
|
+
...referralCode ? {
|
|
164
|
+
referral: {
|
|
165
|
+
connect: {
|
|
166
|
+
id: referralCode
|
|
167
|
+
}
|
|
173
168
|
}
|
|
174
|
-
|
|
169
|
+
} : undefined,
|
|
175
170
|
asBusiness: !!asBusiness,
|
|
176
171
|
source,
|
|
177
172
|
metadata: {
|
|
178
|
-
analytics
|
|
179
|
-
}
|
|
180
|
-
}
|
|
173
|
+
analytics
|
|
174
|
+
}
|
|
175
|
+
}
|
|
181
176
|
});
|
|
182
177
|
};
|
|
183
|
-
const recreateReservationInvoiceAndUpdateReservation = async (previousReservation, body, vehicle, payer)
|
|
178
|
+
const recreateReservationInvoiceAndUpdateReservation = async (previousReservation, body, vehicle, payer)=>{
|
|
184
179
|
const invoiceResult = await createReservationInvoice({
|
|
185
180
|
...body,
|
|
186
181
|
invoiceId: generateId('Invoice'),
|
|
187
182
|
reservationId: previousReservation.id,
|
|
188
183
|
vehicle,
|
|
189
|
-
payer
|
|
184
|
+
payer
|
|
190
185
|
});
|
|
191
186
|
if (!invoiceResult.ok) {
|
|
192
187
|
return invoiceResult;
|
|
@@ -194,16 +189,15 @@ const recreateReservationInvoiceAndUpdateReservation = async (previousReservatio
|
|
|
194
189
|
const invoice = invoiceResult.val;
|
|
195
190
|
const updatedReservation = await prisma.subscriptionReservation.update({
|
|
196
191
|
where: {
|
|
197
|
-
id: previousReservation.id
|
|
192
|
+
id: previousReservation.id
|
|
198
193
|
},
|
|
199
194
|
data: {
|
|
200
195
|
invoice: {
|
|
201
196
|
connect: {
|
|
202
|
-
id: invoice.id
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
197
|
+
id: invoice.id
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
206
201
|
});
|
|
207
202
|
return new Ok(updatedReservation);
|
|
208
203
|
};
|
|
209
|
-
//# sourceMappingURL=fetch-or-create.js.map
|