@driveflux/api-functions 1.0.21 → 1.0.23
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 +29 -24
- package/dist/auth/emails.js +13 -12
- package/dist/auth/formatter.js +5 -5
- package/dist/auth/otp.js +50 -66
- package/dist/auth/register.js +34 -42
- package/dist/auth/tokens.js +55 -58
- package/dist/auth/verifications.js +52 -53
- package/dist/constants.js +1 -0
- package/dist/create-logger.d.ts +2 -0
- package/dist/create-logger.d.ts.map +1 -0
- package/dist/create-logger.js +3 -0
- package/dist/create-logger.js.map +1 -0
- package/dist/mailjet/calls/manage-contacts-in-list.js +6 -5
- package/dist/mailjet/calls/manage-subscription-status.js +5 -4
- package/dist/mailjet/calls/request-service.js +6 -7
- package/dist/mailjet/refresh-email-preferences.js +12 -11
- package/dist/mailjet/set-contact.js +12 -11
- package/dist/mailjet/types.js +2 -1
- package/dist/mailjet/utils/convert-to-array.js +6 -8
- package/dist/mailjet/utils/extract-email-preferences.js +15 -14
- package/dist/mailjet/utils/lists.js +8 -7
- package/dist/mailjet/utils/update-email-references.js +15 -16
- package/dist/notion/client.js +19 -22
- package/dist/notion/helpful.js +9 -6
- package/dist/notion/schemas/block.js +48 -42
- package/dist/notion/schemas/common.js +14 -9
- package/dist/notion/schemas/database.js +60 -62
- package/dist/notion/schemas/emoji.js +2 -1
- package/dist/notion/schemas/file.js +9 -9
- package/dist/notion/schemas/kb.js +6 -5
- package/dist/notion/schemas/page.js +61 -72
- package/dist/notion/schemas/parent.js +5 -4
- package/dist/notion/schemas/user.js +19 -18
- package/dist/reservation/agree.js +7 -6
- package/dist/reservation/checks.js +4 -3
- package/dist/reservation/display-vehicle.js +71 -65
- package/dist/reservation/fetch-or-create.js +54 -48
- package/dist/reservation/invoice.d.ts.map +1 -1
- package/dist/reservation/invoice.js +108 -63
- package/dist/reservation/invoice.js.map +1 -1
- package/dist/reservation/payer.js +6 -5
- package/dist/reservation/reserve.js +4 -3
- package/dist/reservation/types.js +2 -1
- package/dist/reservation/vehicle.js +16 -13
- package/dist/slack.js +29 -24
- package/dist/validation.js +79 -77
- package/dist/vehicle/vehicle-pricing/constants.js +19 -22
- package/dist/vehicle/vehicle-pricing/index.js +42 -28
- package/dist/vehicle/vehicle-pricing/types.js +2 -1
- package/package.json +10 -9
|
@@ -1,75 +1,73 @@
|
|
|
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
|
-
where: {
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
}) : 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'
|
|
8
|
+
? await prisma.displayVehicle.findFirst({ where: { id: displayVehicle } })
|
|
9
|
+
: displayVehicle;
|
|
12
10
|
};
|
|
13
|
-
export const createVehicleFromDisplayVehicle = async (displayVehicle, selectedColor)=>{
|
|
11
|
+
export const createVehicleFromDisplayVehicle = async (displayVehicle, selectedColor) => {
|
|
14
12
|
const dv = await fetchDisplayVehicle(displayVehicle);
|
|
15
|
-
if (!dv || typeof dv !== 'object')
|
|
16
|
-
|
|
17
|
-
|
|
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;
|
|
18
18
|
const vehicleData = {
|
|
19
19
|
id: generateId('Vehicle'),
|
|
20
20
|
...transformBasicVehicleData(dv),
|
|
21
21
|
images: [
|
|
22
|
-
...mainImage ? [
|
|
23
|
-
|
|
24
|
-
] : [],
|
|
25
|
-
...transformImages(dv.images)
|
|
22
|
+
...(mainImage ? [transfromSingleImage(mainImage)] : []),
|
|
23
|
+
...transformImages(dv.images),
|
|
26
24
|
],
|
|
27
25
|
...transformBasePrices(dv.pricing),
|
|
28
26
|
pricing: transformPriceMatrix(dv.type, dv.pricing),
|
|
29
27
|
details: transformDetails(dv.details, selectedColor),
|
|
30
28
|
host: {
|
|
31
29
|
connect: {
|
|
32
|
-
id: dv.defaultHostId
|
|
33
|
-
}
|
|
30
|
+
id: dv.defaultHostId,
|
|
31
|
+
},
|
|
34
32
|
},
|
|
35
33
|
displayVehicle: {
|
|
36
34
|
connect: {
|
|
37
|
-
id: dv.id
|
|
38
|
-
}
|
|
39
|
-
}
|
|
35
|
+
id: dv.id,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
40
38
|
};
|
|
41
39
|
return await prisma.vehicle.create({
|
|
42
40
|
data: vehicleData,
|
|
43
41
|
include: {
|
|
44
|
-
host: true
|
|
45
|
-
}
|
|
42
|
+
host: true,
|
|
43
|
+
},
|
|
46
44
|
});
|
|
47
45
|
};
|
|
48
|
-
export const transfromVehicleDisplayToVehicle = async (displayVehicle, selectedColor)=>{
|
|
46
|
+
export const transfromVehicleDisplayToVehicle = async (displayVehicle, selectedColor) => {
|
|
49
47
|
const dv = await fetchDisplayVehicle(displayVehicle);
|
|
50
|
-
if (!dv || typeof dv !== 'object')
|
|
51
|
-
|
|
52
|
-
|
|
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;
|
|
53
53
|
return {
|
|
54
54
|
id: dv.id,
|
|
55
55
|
...transformBasicVehicleData(dv),
|
|
56
56
|
images: [
|
|
57
|
-
...mainImage ? [
|
|
58
|
-
|
|
59
|
-
] : [],
|
|
60
|
-
...transformImages(dv.images)
|
|
57
|
+
...(mainImage ? [transfromSingleImage(mainImage)] : []),
|
|
58
|
+
...transformImages(dv.images),
|
|
61
59
|
],
|
|
62
60
|
...transformBasePrices(dv.pricing),
|
|
63
61
|
pricing: transformPriceMatrix(dv.type, dv.pricing),
|
|
64
62
|
details: transformDetails(dv.details, selectedColor),
|
|
65
63
|
host: {
|
|
66
64
|
address: {
|
|
67
|
-
state: 'Kuala Lumpur'
|
|
68
|
-
}
|
|
69
|
-
}
|
|
65
|
+
state: 'Kuala Lumpur',
|
|
66
|
+
},
|
|
67
|
+
},
|
|
70
68
|
};
|
|
71
69
|
};
|
|
72
|
-
export const transformBasicVehicleData = (dv)=>{
|
|
70
|
+
export const transformBasicVehicleData = (dv) => {
|
|
73
71
|
return {
|
|
74
72
|
registrationNumber: null,
|
|
75
73
|
featured: false,
|
|
@@ -87,17 +85,17 @@ export const transformBasicVehicleData = (dv)=>{
|
|
|
87
85
|
type: dv.type,
|
|
88
86
|
niceName: `${dv.make} ${dv.vehicleModel} ${dv.variant} ${dv.year}`,
|
|
89
87
|
niceNameShort: `${dv.make} ${dv.vehicleModel}`,
|
|
90
|
-
appliedCoupon: dv.appliedCoupon
|
|
88
|
+
appliedCoupon: dv.appliedCoupon,
|
|
91
89
|
};
|
|
92
90
|
};
|
|
93
|
-
export const transformImages = (images)=>{
|
|
91
|
+
export const transformImages = (images) => {
|
|
94
92
|
return [
|
|
95
93
|
transfromSingleImage(images.exterior[0].url, 'exterior'),
|
|
96
94
|
transfromSingleImage(images.interior[0].url, 'interior'),
|
|
97
|
-
...images.gallery.map((i)=>transfromSingleImage(i.url))
|
|
95
|
+
...images.gallery.map((i) => transfromSingleImage(i.url)),
|
|
98
96
|
];
|
|
99
97
|
};
|
|
100
|
-
const transfromSingleImage = (imageUrl, inspectionType)=>{
|
|
98
|
+
const transfromSingleImage = (imageUrl, inspectionType) => {
|
|
101
99
|
return {
|
|
102
100
|
default: imageUrl,
|
|
103
101
|
blurBase64: null,
|
|
@@ -108,20 +106,20 @@ const transfromSingleImage = (imageUrl, inspectionType)=>{
|
|
|
108
106
|
description: null,
|
|
109
107
|
inspection: !!inspectionType,
|
|
110
108
|
inspectionType: inspectionType || null,
|
|
111
|
-
notActualPhoto: true
|
|
109
|
+
notActualPhoto: true,
|
|
112
110
|
};
|
|
113
111
|
};
|
|
114
|
-
const transformBasePrices = (pricing)=>{
|
|
112
|
+
const transformBasePrices = (pricing) => {
|
|
115
113
|
return {
|
|
116
114
|
basePrice: pricing.matrix.plan36.lite,
|
|
117
115
|
basePricePlan1: pricing.matrix.plan1.lite,
|
|
118
116
|
basePricePlan12: pricing.matrix.plan12.lite,
|
|
119
117
|
basePricePlan24: pricing.matrix.plan24.lite,
|
|
120
118
|
basePricePlan36: pricing.matrix.plan36.lite,
|
|
121
|
-
basePricePlan60: pricing.matrix.plan60.lite
|
|
119
|
+
basePricePlan60: pricing.matrix.plan60.lite,
|
|
122
120
|
};
|
|
123
121
|
};
|
|
124
|
-
const transformPriceMatrix = (vehicleType, pricing)=>{
|
|
122
|
+
const transformPriceMatrix = (vehicleType, pricing) => {
|
|
125
123
|
const baseline = pricing?.matrix.plan36.lite;
|
|
126
124
|
const ultraTier = 'tier1';
|
|
127
125
|
const fluxPriceCoefficient = 25;
|
|
@@ -134,14 +132,16 @@ const transformPriceMatrix = (vehicleType, pricing)=>{
|
|
|
134
132
|
const { availablePlans, availableMileagePackages } = getNonZeroKeys(priceMatrix);
|
|
135
133
|
const pricingController = createPricingController({
|
|
136
134
|
coefficient: fluxPriceCoefficient,
|
|
137
|
-
vehicleType
|
|
135
|
+
vehicleType,
|
|
138
136
|
});
|
|
139
137
|
const startFeeMatrix = excludeServiceFeesFrom(getStartFeeMatrix(pricingController, baseline, flatPricing));
|
|
140
138
|
const hostMatrix = excludeServiceFeesFrom(getHostsMatrix(pricingController, baseline, ultraTier, flatPricing));
|
|
141
139
|
const hostExcessMileage = getHostExcessMileage(pricingController, baseline);
|
|
142
140
|
const fluxPriceMatrix = excludeServiceFeesFrom(getFluxPiceMatrix(pricingController, vehicleType, baseline, hostMatrix, ultraTier, flatPricing));
|
|
143
141
|
const fluxExcessMileage = getFluxExcessMileage(pricingController, baseline);
|
|
144
|
-
const recommendedDeposit = pricing.refundableDeposit || vehicleType === 'motorcycle'
|
|
142
|
+
const recommendedDeposit = pricing.refundableDeposit || vehicleType === 'motorcycle'
|
|
143
|
+
? getRecommendedMotorcycleDeposit(baseline)
|
|
144
|
+
: 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,25 +214,31 @@ const transformDetails = (details, selectColor)=>{
|
|
|
214
214
|
bodyType: details.bodyType,
|
|
215
215
|
transmission: details.transmission,
|
|
216
216
|
engineType: details.fuelType,
|
|
217
|
-
engineCapacity: details.fuelType === 'electric'
|
|
217
|
+
engineCapacity: details.fuelType === 'electric'
|
|
218
|
+
? details.batteryCapacity
|
|
219
|
+
: details.engineCapacity,
|
|
218
220
|
drivetrain: details.drivetrain,
|
|
219
221
|
accelerationTo100km: details.accelerationTo100km,
|
|
220
222
|
fuelConsumptionLitersPer100Km: details.fuelConsumptionLitersPer100Km,
|
|
221
223
|
color,
|
|
222
224
|
features: details.features,
|
|
223
|
-
condition: 'new'
|
|
225
|
+
condition: 'new',
|
|
224
226
|
};
|
|
225
227
|
};
|
|
226
|
-
const excludeServiceFeesFrom = (originalMatrix)=>{
|
|
228
|
+
const excludeServiceFeesFrom = (originalMatrix) => {
|
|
227
229
|
const matrix = {};
|
|
228
|
-
for (const [planKey, planValue] of Object.entries(originalMatrix)){
|
|
229
|
-
if (!planValue)
|
|
230
|
-
|
|
231
|
-
|
|
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)) {
|
|
232
236
|
if (typeof price === 'number') {
|
|
233
|
-
matrix[planKey][mileageKey] =
|
|
237
|
+
matrix[planKey][mileageKey] =
|
|
238
|
+
price / (1 + config.serviceRate);
|
|
234
239
|
}
|
|
235
240
|
}
|
|
236
241
|
}
|
|
237
242
|
return matrix;
|
|
238
243
|
};
|
|
244
|
+
//# sourceMappingURL=display-vehicle.js.map
|
|
@@ -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, } = 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,7 +87,8 @@ 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
|
-
}
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
91
92
|
// We couldn't fetch the reservation, so we create a new one and just log this
|
|
92
93
|
await reportError(error);
|
|
93
94
|
}
|
|
@@ -106,7 +107,7 @@ export const fetchOrCreateReservation = async ({ vehicle, payer, body })=>{
|
|
|
106
107
|
analytics,
|
|
107
108
|
vehicle,
|
|
108
109
|
payer,
|
|
109
|
-
subscribingUser
|
|
110
|
+
subscribingUser,
|
|
110
111
|
});
|
|
111
112
|
if (invoiceResult.err) {
|
|
112
113
|
return invoiceResult;
|
|
@@ -125,63 +126,67 @@ export const fetchOrCreateReservation = async ({ vehicle, payer, body })=>{
|
|
|
125
126
|
deliveryAddresses,
|
|
126
127
|
deliveryDate,
|
|
127
128
|
asBusiness,
|
|
128
|
-
source
|
|
129
|
+
source,
|
|
129
130
|
});
|
|
130
131
|
return new Ok(reservation);
|
|
131
132
|
};
|
|
132
|
-
const createReservation = async ({ reservationId, invoiceId, subscribingUserId, vehicleId, businessId, plan, mileagePackage, couponCode, referralCode, analytics, deliveryAddresses, deliveryDate, asBusiness, source })=>{
|
|
133
|
+
const createReservation = async ({ reservationId, invoiceId, subscribingUserId, vehicleId, businessId, plan, mileagePackage, couponCode, referralCode, analytics, deliveryAddresses, deliveryDate, asBusiness, source, }) => {
|
|
133
134
|
return await prisma.subscriptionReservation.create({
|
|
134
135
|
data: {
|
|
135
136
|
id: reservationId,
|
|
136
137
|
invoice: {
|
|
137
138
|
connect: {
|
|
138
|
-
id: invoiceId
|
|
139
|
-
}
|
|
139
|
+
id: invoiceId,
|
|
140
|
+
},
|
|
140
141
|
},
|
|
141
142
|
user: {
|
|
142
143
|
connect: {
|
|
143
|
-
id: subscribingUserId
|
|
144
|
-
}
|
|
144
|
+
id: subscribingUserId,
|
|
145
|
+
},
|
|
145
146
|
},
|
|
146
147
|
vehicle: {
|
|
147
148
|
connect: {
|
|
148
|
-
id: vehicleId
|
|
149
|
-
}
|
|
149
|
+
id: vehicleId,
|
|
150
|
+
},
|
|
150
151
|
},
|
|
151
|
-
...businessId
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
152
|
+
...(businessId
|
|
153
|
+
? {
|
|
154
|
+
business: {
|
|
155
|
+
connect: {
|
|
156
|
+
id: businessId,
|
|
157
|
+
},
|
|
158
|
+
},
|
|
156
159
|
}
|
|
157
|
-
|
|
160
|
+
: undefined),
|
|
158
161
|
plan,
|
|
159
162
|
mileagePackage,
|
|
160
163
|
couponCode: couponCode,
|
|
161
164
|
deliveryAddresses: deliveryAddresses,
|
|
162
165
|
deliveryDate: deliveryDate,
|
|
163
|
-
...referralCode
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
...(referralCode
|
|
167
|
+
? {
|
|
168
|
+
referral: {
|
|
169
|
+
connect: {
|
|
170
|
+
id: referralCode,
|
|
171
|
+
},
|
|
172
|
+
},
|
|
168
173
|
}
|
|
169
|
-
|
|
174
|
+
: undefined),
|
|
170
175
|
asBusiness: !!asBusiness,
|
|
171
176
|
source,
|
|
172
177
|
metadata: {
|
|
173
|
-
analytics
|
|
174
|
-
}
|
|
175
|
-
}
|
|
178
|
+
analytics,
|
|
179
|
+
},
|
|
180
|
+
},
|
|
176
181
|
});
|
|
177
182
|
};
|
|
178
|
-
const recreateReservationInvoiceAndUpdateReservation = async (previousReservation, body, vehicle, payer)=>{
|
|
183
|
+
const recreateReservationInvoiceAndUpdateReservation = async (previousReservation, body, vehicle, payer) => {
|
|
179
184
|
const invoiceResult = await createReservationInvoice({
|
|
180
185
|
...body,
|
|
181
186
|
invoiceId: generateId('Invoice'),
|
|
182
187
|
reservationId: previousReservation.id,
|
|
183
188
|
vehicle,
|
|
184
|
-
payer
|
|
189
|
+
payer,
|
|
185
190
|
});
|
|
186
191
|
if (!invoiceResult.ok) {
|
|
187
192
|
return invoiceResult;
|
|
@@ -189,15 +194,16 @@ const recreateReservationInvoiceAndUpdateReservation = async (previousReservatio
|
|
|
189
194
|
const invoice = invoiceResult.val;
|
|
190
195
|
const updatedReservation = await prisma.subscriptionReservation.update({
|
|
191
196
|
where: {
|
|
192
|
-
id: previousReservation.id
|
|
197
|
+
id: previousReservation.id,
|
|
193
198
|
},
|
|
194
199
|
data: {
|
|
195
200
|
invoice: {
|
|
196
201
|
connect: {
|
|
197
|
-
id: invoice.id
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
202
|
+
id: invoice.id,
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
},
|
|
201
206
|
});
|
|
202
207
|
return new Ok(updatedReservation);
|
|
203
208
|
};
|
|
209
|
+
//# sourceMappingURL=fetch-or-create.js.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;
|
|
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;AAK3D,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,WAAW,GACX,iBAAiB,CACnB,GAAG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,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;CACtB,CAAA;AAID,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,CAoJzD,CAAA"}
|