• Is order made by self validator

    Parameters

    • config: {
          authSecrets: AuthSecrets;
          authenticate: AuthenticationFunction;
      }

      authentication config

      • authSecrets: AuthSecrets
      • authenticate: AuthenticationFunction
    • orderService: OrderDataService

      injected service use to handle order related operations

      • getOneOrder
    • logger: Logger

      injected logger use to handle logging

    • context: AdapterHandlerContext

      request context [headers, body, params, query].

      • params.orderId is required

    Returns Promise<StatusCodes>

    200 Status OK

    Description

    This validator checks if the order is made by the user who is requesting the order by applying the following steps in sequence:

    1. Get orderId from params context

    2. Get order (orderService.getOneOrder) from database

    3. Authenticate user

    4. Check if user is app, if true, throw NBError

    5. Check if order.customer.userId is the same as userId, if true, return StatusCodes.OK

    Throws

    400 NBError Bad Request

    • order: orderId not given

    Throws

    404 NBError Not Found

    • order: orderId not found

    Throws

    401 NBError Unauthorized

    • authenticate error

    Throws

    403 NBError Forbidden

    • order: app access token is not allowed
    • order: orderId=${order.id} does not belong to the user

Generated using TypeDoc