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