@driveflux/api-functions 1.0.52 → 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.
@@ -19,4 +19,5 @@ export const handleAgreeToTerms = async ({ agreedToTerms, subscribingUser, ipAdd
19
19
  }
20
20
  });
21
21
  }
22
+ return subscribingUser;
22
23
  };
@@ -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 checkIfUserCanReserve = async ({ requestUser, subscribingUser })=>{
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 { Ok } from '@driveflux/result';
1
+ import { makeProblem, PROBLEM_UNAUTHORIZED } from '@driveflux/problem';
2
+ import { Err, Ok } from '@driveflux/result';
2
3
  import { handleAgreeToTerms } from './agree.js';
3
- import { checkIfUserCanReserve } from './checks.js';
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 checkIfUserCanReserve(body);
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.52",
3
+ "version": "1.0.53",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./notion": {