@driveflux/api-functions 0.0.6 → 0.0.7-next.1
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 +73 -327
- package/dist/auth/emails.js +43 -210
- package/dist/auth/formatter.js +11 -11
- package/dist/auth/otp.js +122 -392
- package/dist/auth/register.js +100 -396
- package/dist/auth/tokens.d.ts +3 -3
- package/dist/auth/tokens.js +115 -430
- package/dist/auth/verifications.d.ts.map +1 -1
- package/dist/auth/verifications.js +191 -514
- package/dist/auth/verifications.js.map +1 -1
- package/dist/constants.js +5 -4
- package/dist/mailjet/calls/manage-contacts-in-list.js +22 -166
- package/dist/mailjet/calls/manage-subscription-status.js +13 -153
- package/dist/mailjet/calls/request-service.d.ts +1 -1
- package/dist/mailjet/calls/request-service.d.ts.map +1 -1
- package/dist/mailjet/calls/request-service.js +18 -183
- package/dist/mailjet/refresh-email-preferences.js +26 -225
- package/dist/mailjet/set-contact.js +23 -214
- package/dist/mailjet/types.js +2 -1
- package/dist/mailjet/utils/convert-to-array.js +9 -58
- package/dist/mailjet/utils/extract-email-preferences.js +41 -217
- package/dist/mailjet/utils/lists.js +30 -249
- package/dist/mailjet/utils/update-email-references.js +27 -208
- package/dist/notion/client.js +48 -197
- package/dist/notion/helpful.js +29 -170
- package/dist/notion/schemas/block.js +49 -43
- package/dist/notion/schemas/common.js +17 -14
- package/dist/notion/schemas/database.js +125 -159
- package/dist/notion/schemas/emoji.js +3 -2
- package/dist/notion/schemas/file.js +10 -10
- package/dist/notion/schemas/kb.js +9 -8
- package/dist/notion/schemas/page.js +126 -171
- package/dist/notion/schemas/parent.js +9 -8
- package/dist/notion/schemas/user.js +21 -20
- package/dist/reservation/agree.js +19 -158
- package/dist/reservation/checks.js +23 -178
- package/dist/reservation/display-vehicle.d.ts +37 -37
- package/dist/reservation/display-vehicle.d.ts.map +1 -1
- package/dist/reservation/display-vehicle.js +142 -514
- package/dist/reservation/fetch-or-create.js +197 -482
- package/dist/reservation/invoice.js +198 -496
- package/dist/reservation/payer.js +28 -177
- package/dist/reservation/reserve.js +31 -191
- package/dist/reservation/types.js +2 -1
- package/dist/reservation/vehicle.js +24 -186
- package/dist/slack.d.ts +2 -2
- package/dist/slack.d.ts.map +1 -1
- package/dist/slack.js +67 -273
- package/dist/validation.js +81 -139
- package/dist/vehicle/vehicle-pricing/constants.js +33 -36
- package/dist/vehicle/vehicle-pricing/index.js +99 -257
- package/dist/vehicle/vehicle-pricing/types.js +2 -1
- package/package.json +12 -12
|
@@ -1,187 +1,38 @@
|
|
|
1
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
-
try {
|
|
3
|
-
var info = gen[key](arg);
|
|
4
|
-
var value = info.value;
|
|
5
|
-
} catch (error) {
|
|
6
|
-
reject(error);
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
if (info.done) {
|
|
10
|
-
resolve(value);
|
|
11
|
-
} else {
|
|
12
|
-
Promise.resolve(value).then(_next, _throw);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function _async_to_generator(fn) {
|
|
16
|
-
return function() {
|
|
17
|
-
var self = this, args = arguments;
|
|
18
|
-
return new Promise(function(resolve, reject) {
|
|
19
|
-
var gen = fn.apply(self, args);
|
|
20
|
-
function _next(value) {
|
|
21
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
-
}
|
|
23
|
-
function _throw(err) {
|
|
24
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
-
}
|
|
26
|
-
_next(undefined);
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function _ts_generator(thisArg, body) {
|
|
31
|
-
var f, y, t, _ = {
|
|
32
|
-
label: 0,
|
|
33
|
-
sent: function() {
|
|
34
|
-
if (t[0] & 1) throw t[1];
|
|
35
|
-
return t[1];
|
|
36
|
-
},
|
|
37
|
-
trys: [],
|
|
38
|
-
ops: []
|
|
39
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
40
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
41
|
-
return this;
|
|
42
|
-
}), g;
|
|
43
|
-
function verb(n) {
|
|
44
|
-
return function(v) {
|
|
45
|
-
return step([
|
|
46
|
-
n,
|
|
47
|
-
v
|
|
48
|
-
]);
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
function step(op) {
|
|
52
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
53
|
-
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
54
|
-
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;
|
|
55
|
-
if (y = 0, t) op = [
|
|
56
|
-
op[0] & 2,
|
|
57
|
-
t.value
|
|
58
|
-
];
|
|
59
|
-
switch(op[0]){
|
|
60
|
-
case 0:
|
|
61
|
-
case 1:
|
|
62
|
-
t = op;
|
|
63
|
-
break;
|
|
64
|
-
case 4:
|
|
65
|
-
_.label++;
|
|
66
|
-
return {
|
|
67
|
-
value: op[1],
|
|
68
|
-
done: false
|
|
69
|
-
};
|
|
70
|
-
case 5:
|
|
71
|
-
_.label++;
|
|
72
|
-
y = op[1];
|
|
73
|
-
op = [
|
|
74
|
-
0
|
|
75
|
-
];
|
|
76
|
-
continue;
|
|
77
|
-
case 7:
|
|
78
|
-
op = _.ops.pop();
|
|
79
|
-
_.trys.pop();
|
|
80
|
-
continue;
|
|
81
|
-
default:
|
|
82
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
83
|
-
_ = 0;
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
87
|
-
_.label = op[1];
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
91
|
-
_.label = t[1];
|
|
92
|
-
t = op;
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
if (t && _.label < t[2]) {
|
|
96
|
-
_.label = t[2];
|
|
97
|
-
_.ops.push(op);
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
if (t[2]) _.ops.pop();
|
|
101
|
-
_.trys.pop();
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
op = body.call(thisArg, _);
|
|
105
|
-
} catch (e) {
|
|
106
|
-
op = [
|
|
107
|
-
6,
|
|
108
|
-
e
|
|
109
|
-
];
|
|
110
|
-
y = 0;
|
|
111
|
-
} finally{
|
|
112
|
-
f = t = 0;
|
|
113
|
-
}
|
|
114
|
-
if (op[0] & 5) throw op[1];
|
|
115
|
-
return {
|
|
116
|
-
value: op[0] ? op[1] : void 0,
|
|
117
|
-
done: true
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
1
|
import { prisma } from '@driveflux/db';
|
|
122
|
-
import { makeProblem, PROBLEM_CONDITION_FAILED, PROBLEM_NOT_FOUND } from '@driveflux/problem';
|
|
2
|
+
import { makeProblem, PROBLEM_CONDITION_FAILED, PROBLEM_NOT_FOUND, } from '@driveflux/problem';
|
|
123
3
|
import { Err, Ok } from '@driveflux/result';
|
|
124
|
-
export
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
];
|
|
137
|
-
if (!subscribingUser.businessId) {
|
|
138
|
-
return [
|
|
139
|
-
2,
|
|
140
|
-
new Err(makeProblem(PROBLEM_CONDITION_FAILED, 'You are not associated with any business'))
|
|
141
|
-
];
|
|
142
|
-
}
|
|
143
|
-
return [
|
|
144
|
-
4,
|
|
145
|
-
prisma.business.findUnique({
|
|
146
|
-
where: {
|
|
147
|
-
id: subscribingUser.businessId
|
|
148
|
-
}
|
|
149
|
-
})
|
|
150
|
-
];
|
|
151
|
-
case 1:
|
|
152
|
-
// load business
|
|
153
|
-
business = _state.sent();
|
|
154
|
-
if (!business) {
|
|
155
|
-
return [
|
|
156
|
-
2,
|
|
157
|
-
new Err(makeProblem(PROBLEM_NOT_FOUND, "The business ".concat(subscribingUser.businessId, " was not found.")))
|
|
158
|
-
];
|
|
159
|
-
}
|
|
160
|
-
payer = business;
|
|
161
|
-
_state.label = 2;
|
|
162
|
-
case 2:
|
|
163
|
-
// Sanity check
|
|
164
|
-
subscriberSanityResult = checkPayerObjectSanity(payer);
|
|
165
|
-
if (subscriberSanityResult.err) {
|
|
166
|
-
return [
|
|
167
|
-
2,
|
|
168
|
-
subscriberSanityResult
|
|
169
|
-
];
|
|
170
|
-
}
|
|
171
|
-
return [
|
|
172
|
-
2,
|
|
173
|
-
new Ok(payer)
|
|
174
|
-
];
|
|
175
|
-
}
|
|
4
|
+
export const getPayer = async ({ subscribingUser, asBusiness, }) => {
|
|
5
|
+
let business = null;
|
|
6
|
+
let payer = subscribingUser;
|
|
7
|
+
if (asBusiness) {
|
|
8
|
+
if (!subscribingUser.businessId) {
|
|
9
|
+
return new Err(makeProblem(PROBLEM_CONDITION_FAILED, 'You are not associated with any business'));
|
|
10
|
+
}
|
|
11
|
+
// load business
|
|
12
|
+
business = await prisma.business.findUnique({
|
|
13
|
+
where: {
|
|
14
|
+
id: subscribingUser.businessId,
|
|
15
|
+
},
|
|
176
16
|
});
|
|
177
|
-
|
|
17
|
+
if (!business) {
|
|
18
|
+
return new Err(makeProblem(PROBLEM_NOT_FOUND, `The business ${subscribingUser.businessId} was not found.`));
|
|
19
|
+
}
|
|
20
|
+
payer = business;
|
|
21
|
+
}
|
|
22
|
+
// Sanity check
|
|
23
|
+
const subscriberSanityResult = checkPayerObjectSanity(payer);
|
|
24
|
+
if (subscriberSanityResult.err) {
|
|
25
|
+
return subscriberSanityResult;
|
|
26
|
+
}
|
|
27
|
+
return new Ok(payer);
|
|
178
28
|
};
|
|
179
|
-
|
|
29
|
+
const checkPayerObjectSanity = (subscriber) => {
|
|
180
30
|
if (!subscriber.email) {
|
|
181
|
-
return new Err(makeProblem(PROBLEM_CONDITION_FAILED,
|
|
31
|
+
return new Err(makeProblem(PROBLEM_CONDITION_FAILED, `Subscriber ${subscriber.id} has no email. Please add a verified email first.`));
|
|
182
32
|
}
|
|
183
33
|
if (!subscriber.phoneNumber) {
|
|
184
|
-
return new Err(makeProblem(PROBLEM_CONDITION_FAILED,
|
|
34
|
+
return new Err(makeProblem(PROBLEM_CONDITION_FAILED, `Subscriber ${subscriber.id} has no phone number. Please add a phone number first.`));
|
|
185
35
|
}
|
|
186
36
|
return new Ok(true);
|
|
187
37
|
};
|
|
38
|
+
//# sourceMappingURL=payer.js.map
|
|
@@ -1,204 +1,44 @@
|
|
|
1
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
-
try {
|
|
3
|
-
var info = gen[key](arg);
|
|
4
|
-
var value = info.value;
|
|
5
|
-
} catch (error) {
|
|
6
|
-
reject(error);
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
if (info.done) {
|
|
10
|
-
resolve(value);
|
|
11
|
-
} else {
|
|
12
|
-
Promise.resolve(value).then(_next, _throw);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function _async_to_generator(fn) {
|
|
16
|
-
return function() {
|
|
17
|
-
var self = this, args = arguments;
|
|
18
|
-
return new Promise(function(resolve, reject) {
|
|
19
|
-
var gen = fn.apply(self, args);
|
|
20
|
-
function _next(value) {
|
|
21
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
-
}
|
|
23
|
-
function _throw(err) {
|
|
24
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
-
}
|
|
26
|
-
_next(undefined);
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function _ts_generator(thisArg, body) {
|
|
31
|
-
var f, y, t, _ = {
|
|
32
|
-
label: 0,
|
|
33
|
-
sent: function() {
|
|
34
|
-
if (t[0] & 1) throw t[1];
|
|
35
|
-
return t[1];
|
|
36
|
-
},
|
|
37
|
-
trys: [],
|
|
38
|
-
ops: []
|
|
39
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
40
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
41
|
-
return this;
|
|
42
|
-
}), g;
|
|
43
|
-
function verb(n) {
|
|
44
|
-
return function(v) {
|
|
45
|
-
return step([
|
|
46
|
-
n,
|
|
47
|
-
v
|
|
48
|
-
]);
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
function step(op) {
|
|
52
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
53
|
-
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
54
|
-
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;
|
|
55
|
-
if (y = 0, t) op = [
|
|
56
|
-
op[0] & 2,
|
|
57
|
-
t.value
|
|
58
|
-
];
|
|
59
|
-
switch(op[0]){
|
|
60
|
-
case 0:
|
|
61
|
-
case 1:
|
|
62
|
-
t = op;
|
|
63
|
-
break;
|
|
64
|
-
case 4:
|
|
65
|
-
_.label++;
|
|
66
|
-
return {
|
|
67
|
-
value: op[1],
|
|
68
|
-
done: false
|
|
69
|
-
};
|
|
70
|
-
case 5:
|
|
71
|
-
_.label++;
|
|
72
|
-
y = op[1];
|
|
73
|
-
op = [
|
|
74
|
-
0
|
|
75
|
-
];
|
|
76
|
-
continue;
|
|
77
|
-
case 7:
|
|
78
|
-
op = _.ops.pop();
|
|
79
|
-
_.trys.pop();
|
|
80
|
-
continue;
|
|
81
|
-
default:
|
|
82
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
83
|
-
_ = 0;
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
87
|
-
_.label = op[1];
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
91
|
-
_.label = t[1];
|
|
92
|
-
t = op;
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
if (t && _.label < t[2]) {
|
|
96
|
-
_.label = t[2];
|
|
97
|
-
_.ops.push(op);
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
if (t[2]) _.ops.pop();
|
|
101
|
-
_.trys.pop();
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
op = body.call(thisArg, _);
|
|
105
|
-
} catch (e) {
|
|
106
|
-
op = [
|
|
107
|
-
6,
|
|
108
|
-
e
|
|
109
|
-
];
|
|
110
|
-
y = 0;
|
|
111
|
-
} finally{
|
|
112
|
-
f = t = 0;
|
|
113
|
-
}
|
|
114
|
-
if (op[0] & 5) throw op[1];
|
|
115
|
-
return {
|
|
116
|
-
value: op[0] ? op[1] : void 0,
|
|
117
|
-
done: true
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
1
|
import { Ok } from '@driveflux/result';
|
|
122
2
|
import { handleAgreeToTerms } from './agree';
|
|
123
3
|
import { checkIfUserCanReserve } from './checks';
|
|
124
4
|
import { fetchOrCreateReservation } from './fetch-or-create';
|
|
125
5
|
import { getPayer } from './payer';
|
|
126
6
|
import { getVehicle } from './vehicle';
|
|
127
|
-
|
|
7
|
+
const processBody = (body) => {
|
|
128
8
|
// Switch mileage package
|
|
129
9
|
if (body.plan === 'plan1' || body.plan === 'planWeekly') {
|
|
130
10
|
body.mileagePackage = 'unlimited';
|
|
131
11
|
}
|
|
132
12
|
return body;
|
|
133
13
|
};
|
|
134
|
-
export
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
payerResult
|
|
164
|
-
];
|
|
165
|
-
}
|
|
166
|
-
payer = payerResult.val;
|
|
167
|
-
return [
|
|
168
|
-
4,
|
|
169
|
-
getVehicle(vehicleId, body, requesterAbility)
|
|
170
|
-
];
|
|
171
|
-
case 4:
|
|
172
|
-
vehicleResult = _state.sent();
|
|
173
|
-
if (vehicleResult.err) {
|
|
174
|
-
return [
|
|
175
|
-
2,
|
|
176
|
-
vehicleResult
|
|
177
|
-
];
|
|
178
|
-
}
|
|
179
|
-
vehicle = vehicleResult.val;
|
|
180
|
-
return [
|
|
181
|
-
4,
|
|
182
|
-
fetchOrCreateReservation({
|
|
183
|
-
vehicle: vehicle,
|
|
184
|
-
payer: payer,
|
|
185
|
-
body: body
|
|
186
|
-
})
|
|
187
|
-
];
|
|
188
|
-
case 5:
|
|
189
|
-
reservationResult = _state.sent();
|
|
190
|
-
if (reservationResult.err) {
|
|
191
|
-
return [
|
|
192
|
-
2,
|
|
193
|
-
reservationResult
|
|
194
|
-
];
|
|
195
|
-
}
|
|
196
|
-
reservation = reservationResult.val;
|
|
197
|
-
return [
|
|
198
|
-
2,
|
|
199
|
-
new Ok(reservation)
|
|
200
|
-
];
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
})();
|
|
14
|
+
export const reserveVehicle = async (vehicleId, unprocessed) => {
|
|
15
|
+
const body = processBody(unprocessed);
|
|
16
|
+
// Agree to terms if not done yet
|
|
17
|
+
await handleAgreeToTerms(body);
|
|
18
|
+
// Check if the user can reserve
|
|
19
|
+
const requesterAbility = await checkIfUserCanReserve(body);
|
|
20
|
+
// Payer
|
|
21
|
+
const payerResult = await getPayer(body);
|
|
22
|
+
if (payerResult.err) {
|
|
23
|
+
return payerResult;
|
|
24
|
+
}
|
|
25
|
+
const payer = payerResult.val;
|
|
26
|
+
// Vehicle
|
|
27
|
+
const vehicleResult = await getVehicle(vehicleId, body, requesterAbility);
|
|
28
|
+
if (vehicleResult.err) {
|
|
29
|
+
return vehicleResult;
|
|
30
|
+
}
|
|
31
|
+
const vehicle = vehicleResult.val;
|
|
32
|
+
// Make or fetch the reservation
|
|
33
|
+
const reservationResult = await fetchOrCreateReservation({
|
|
34
|
+
vehicle,
|
|
35
|
+
payer,
|
|
36
|
+
body,
|
|
37
|
+
});
|
|
38
|
+
if (reservationResult.err) {
|
|
39
|
+
return reservationResult;
|
|
40
|
+
}
|
|
41
|
+
const reservation = reservationResult.val;
|
|
42
|
+
return new Ok(reservation);
|
|
204
43
|
};
|
|
44
|
+
//# sourceMappingURL=reserve.js.map
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {};
|
|
2
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -1,194 +1,32 @@
|
|
|
1
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
-
try {
|
|
3
|
-
var info = gen[key](arg);
|
|
4
|
-
var value = info.value;
|
|
5
|
-
} catch (error) {
|
|
6
|
-
reject(error);
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
if (info.done) {
|
|
10
|
-
resolve(value);
|
|
11
|
-
} else {
|
|
12
|
-
Promise.resolve(value).then(_next, _throw);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function _async_to_generator(fn) {
|
|
16
|
-
return function() {
|
|
17
|
-
var self = this, args = arguments;
|
|
18
|
-
return new Promise(function(resolve, reject) {
|
|
19
|
-
var gen = fn.apply(self, args);
|
|
20
|
-
function _next(value) {
|
|
21
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
-
}
|
|
23
|
-
function _throw(err) {
|
|
24
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
-
}
|
|
26
|
-
_next(undefined);
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function _ts_generator(thisArg, body) {
|
|
31
|
-
var f, y, t, _ = {
|
|
32
|
-
label: 0,
|
|
33
|
-
sent: function() {
|
|
34
|
-
if (t[0] & 1) throw t[1];
|
|
35
|
-
return t[1];
|
|
36
|
-
},
|
|
37
|
-
trys: [],
|
|
38
|
-
ops: []
|
|
39
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
40
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
41
|
-
return this;
|
|
42
|
-
}), g;
|
|
43
|
-
function verb(n) {
|
|
44
|
-
return function(v) {
|
|
45
|
-
return step([
|
|
46
|
-
n,
|
|
47
|
-
v
|
|
48
|
-
]);
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
function step(op) {
|
|
52
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
53
|
-
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
54
|
-
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;
|
|
55
|
-
if (y = 0, t) op = [
|
|
56
|
-
op[0] & 2,
|
|
57
|
-
t.value
|
|
58
|
-
];
|
|
59
|
-
switch(op[0]){
|
|
60
|
-
case 0:
|
|
61
|
-
case 1:
|
|
62
|
-
t = op;
|
|
63
|
-
break;
|
|
64
|
-
case 4:
|
|
65
|
-
_.label++;
|
|
66
|
-
return {
|
|
67
|
-
value: op[1],
|
|
68
|
-
done: false
|
|
69
|
-
};
|
|
70
|
-
case 5:
|
|
71
|
-
_.label++;
|
|
72
|
-
y = op[1];
|
|
73
|
-
op = [
|
|
74
|
-
0
|
|
75
|
-
];
|
|
76
|
-
continue;
|
|
77
|
-
case 7:
|
|
78
|
-
op = _.ops.pop();
|
|
79
|
-
_.trys.pop();
|
|
80
|
-
continue;
|
|
81
|
-
default:
|
|
82
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
83
|
-
_ = 0;
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
87
|
-
_.label = op[1];
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
91
|
-
_.label = t[1];
|
|
92
|
-
t = op;
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
if (t && _.label < t[2]) {
|
|
96
|
-
_.label = t[2];
|
|
97
|
-
_.ops.push(op);
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
if (t[2]) _.ops.pop();
|
|
101
|
-
_.trys.pop();
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
op = body.call(thisArg, _);
|
|
105
|
-
} catch (e) {
|
|
106
|
-
op = [
|
|
107
|
-
6,
|
|
108
|
-
e
|
|
109
|
-
];
|
|
110
|
-
y = 0;
|
|
111
|
-
} finally{
|
|
112
|
-
f = t = 0;
|
|
113
|
-
}
|
|
114
|
-
if (op[0] & 5) throw op[1];
|
|
115
|
-
return {
|
|
116
|
-
value: op[0] ? op[1] : void 0,
|
|
117
|
-
done: true
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
1
|
import { subject } from '@casl/ability';
|
|
122
2
|
import { prisma } from '@driveflux/db';
|
|
123
3
|
import { makeProblem, PROBLEM_NOT_FOUND } from '@driveflux/problem';
|
|
124
4
|
import { Err, Ok } from '@driveflux/result';
|
|
125
5
|
import { checkIfVehicleIsAvailableForReservation } from './checks';
|
|
126
6
|
import { createVehicleFromDisplayVehicle } from './display-vehicle';
|
|
127
|
-
export
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
];
|
|
142
|
-
case 1:
|
|
143
|
-
_tmp = _state.sent();
|
|
144
|
-
return [
|
|
145
|
-
3,
|
|
146
|
-
4
|
|
147
|
-
];
|
|
148
|
-
case 2:
|
|
149
|
-
return [
|
|
150
|
-
4,
|
|
151
|
-
prisma.vehicle.findUnique({
|
|
152
|
-
where: {
|
|
153
|
-
id: id
|
|
154
|
-
},
|
|
155
|
-
include: {
|
|
156
|
-
host: {
|
|
157
|
-
select: {
|
|
158
|
-
id: true
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
})
|
|
163
|
-
];
|
|
164
|
-
case 3:
|
|
165
|
-
_tmp = _state.sent();
|
|
166
|
-
_state.label = 4;
|
|
167
|
-
case 4:
|
|
168
|
-
vehicle = _tmp;
|
|
169
|
-
if (!vehicle) {
|
|
170
|
-
return [
|
|
171
|
-
2,
|
|
172
|
-
new Err(makeProblem(PROBLEM_NOT_FOUND, 'Vehicle not found'))
|
|
173
|
-
];
|
|
174
|
-
}
|
|
175
|
-
return [
|
|
176
|
-
4,
|
|
177
|
-
checkIfVehicleIsAvailableForReservation(vehicle, plan, requesterAbility.can('reserveDelistedVehicle', subject('User', requestUser)))
|
|
178
|
-
];
|
|
179
|
-
case 5:
|
|
180
|
-
vehicleResult = _state.sent();
|
|
181
|
-
if (vehicleResult.err) {
|
|
182
|
-
return [
|
|
183
|
-
2,
|
|
184
|
-
vehicleResult
|
|
185
|
-
];
|
|
186
|
-
}
|
|
187
|
-
return [
|
|
188
|
-
2,
|
|
189
|
-
new Ok(vehicle)
|
|
190
|
-
];
|
|
191
|
-
}
|
|
7
|
+
export const getVehicle = async (id, { selectedColor, plan, requestUser, }, requesterAbility) => {
|
|
8
|
+
const vehicle = id.startsWith('DV_')
|
|
9
|
+
? await createVehicleFromDisplayVehicle(id, selectedColor || undefined)
|
|
10
|
+
: await prisma.vehicle.findUnique({
|
|
11
|
+
where: {
|
|
12
|
+
id,
|
|
13
|
+
},
|
|
14
|
+
include: {
|
|
15
|
+
host: {
|
|
16
|
+
select: {
|
|
17
|
+
id: true,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
192
21
|
});
|
|
193
|
-
|
|
22
|
+
if (!vehicle) {
|
|
23
|
+
return new Err(makeProblem(PROBLEM_NOT_FOUND, 'Vehicle not found'));
|
|
24
|
+
}
|
|
25
|
+
// Check if the vehicle can be reserved
|
|
26
|
+
const vehicleResult = await checkIfVehicleIsAvailableForReservation(vehicle, plan, requesterAbility.can('reserveDelistedVehicle', subject('User', requestUser)));
|
|
27
|
+
if (vehicleResult.err) {
|
|
28
|
+
return vehicleResult;
|
|
29
|
+
}
|
|
30
|
+
return new Ok(vehicle);
|
|
194
31
|
};
|
|
32
|
+
//# sourceMappingURL=vehicle.js.map
|
package/dist/slack.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ declare global {
|
|
|
6
6
|
*
|
|
7
7
|
* @deprecated Use slackLater instead and commitSlack to commit
|
|
8
8
|
*/
|
|
9
|
-
export declare const slack: (message: string, channel?: string | undefined) => Promise<import("@driveflux/fetch").EnhandedFetchResult<object, import("
|
|
9
|
+
export declare const slack: (message: string, channel?: string | undefined) => Promise<import("@driveflux/fetch").EnhandedFetchResult<object, import("../../../packages/problem/dist/index.js").Problem>>;
|
|
10
10
|
export declare const getSlackBlocks: (channel?: string) => Set<KnownBlock> | Map<string, Set<KnownBlock>> | undefined;
|
|
11
11
|
/**
|
|
12
12
|
* Naive implementation, however, for now (uncrowded serverless env), this works
|
|
@@ -14,6 +14,6 @@ export declare const getSlackBlocks: (channel?: string) => Set<KnownBlock> | Map
|
|
|
14
14
|
* @param channel
|
|
15
15
|
*/
|
|
16
16
|
export declare function slackLater(blocks: string | KnownBlock | KnownBlock[], channel?: string): void;
|
|
17
|
-
export declare function sendSlackMessages(channel: string, blocks: KnownBlock[]): Promise<import("@driveflux/fetch").EnhandedFetchResult<object, import("
|
|
17
|
+
export declare function sendSlackMessages(channel: string, blocks: KnownBlock[]): Promise<import("@driveflux/fetch").EnhandedFetchResult<object, import("../../../packages/problem/dist/index.js").Problem>>;
|
|
18
18
|
export declare const commitSlack: () => void;
|
|
19
19
|
//# sourceMappingURL=slack.d.ts.map
|