@driveflux/api-functions 1.0.51 → 1.0.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { ForbiddenError, subject } from '@casl/ability';
|
|
2
1
|
import { buildOrDefineAbility } from '@driveflux/auth/authorization';
|
|
3
2
|
import { makeProblem, PROBLEM_CONDITION_FAILED, PROBLEM_RESOURCE_BUSY } from '@driveflux/problem';
|
|
4
3
|
import { Err, Ok } from '@driveflux/result';
|
|
5
|
-
export const
|
|
4
|
+
export const getUserAbility = async ({ requestUser })=>{
|
|
6
5
|
// Check if the user can reserve
|
|
7
6
|
const requestUserAbility = await buildOrDefineAbility(requestUser);
|
|
8
|
-
// Check if user can reserve
|
|
9
|
-
ForbiddenError.from(requestUserAbility).throwUnlessCan('reserveVehicle', subject('User', subscribingUser));
|
|
10
7
|
return requestUserAbility;
|
|
11
8
|
};
|
|
12
9
|
export const checkIfVehicleIsAvailableForReservation = async (vehicle, plan, allowDelisted)=>{
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { makeProblem, PROBLEM_UNAUTHORIZED } from '@driveflux/problem';
|
|
2
|
+
import { Err, Ok } from '@driveflux/result';
|
|
2
3
|
import { handleAgreeToTerms } from './agree.js';
|
|
3
|
-
import {
|
|
4
|
+
import { getUserAbility } from './checks.js';
|
|
4
5
|
import { ensureUserBillingAddress } from './ensure-user-billing-address.js';
|
|
5
6
|
import { fetchOrCreateReservation } from './fetch-or-create.js';
|
|
6
7
|
import { getPayer } from './payer.js';
|
|
@@ -16,9 +17,12 @@ const processBody = (body)=>{
|
|
|
16
17
|
export const reserveVehicle = async (vehicleId, unprocessed)=>{
|
|
17
18
|
const body = processBody(unprocessed);
|
|
18
19
|
// Agree to terms if not done yet
|
|
19
|
-
await handleAgreeToTerms(body);
|
|
20
|
+
body.subscribingUser = await handleAgreeToTerms(body);
|
|
20
21
|
// Check if the user can reserve
|
|
21
|
-
const requesterAbility = await
|
|
22
|
+
const requesterAbility = await getUserAbility(body);
|
|
23
|
+
if (body.subscribingUser.banned) {
|
|
24
|
+
return new Err(makeProblem(PROBLEM_UNAUTHORIZED, 'You are banned from reserving vehicles'));
|
|
25
|
+
}
|
|
22
26
|
// Payer
|
|
23
27
|
const payerResult = await getPayer(body);
|
|
24
28
|
if (payerResult.err) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@driveflux/api-functions",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.53",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./notion": {
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"@driveflux/db": "4.0.5",
|
|
81
81
|
"@driveflux/email": "7.0.5",
|
|
82
82
|
"@driveflux/email-templates": "1.0.5",
|
|
83
|
-
"@driveflux/engine": "1.0.
|
|
83
|
+
"@driveflux/engine": "1.0.17",
|
|
84
84
|
"@driveflux/fetch": "8.0.0",
|
|
85
85
|
"@driveflux/format-money": "7.0.0",
|
|
86
86
|
"@driveflux/problem": "6.0.0",
|