export async function handler()

in typescript/src/user/user.ts [111:153]


export async function handler(
  httpRequest: APIGatewayProxyEvent,
): Promise<APIGatewayProxyResult> {
  try {
    const apiKeys = await apiKeysConfig();
    const authToken = getAuthToken(httpRequest.headers);

    let userId: string;

    if (authToken && apiKeys.includes(authToken)) {
      if (httpRequest.pathParameters && httpRequest.pathParameters['userId']) {
        userId = httpRequest.pathParameters['userId'];
      } else {
        return HTTPResponses.INVALID_REQUEST;
      }
    } else {
      const resolution: UserIdResolution = await getUserId(httpRequest.headers);
      switch (resolution.status) {
        case 'incorrect-token': {
          return HTTPResponses.UNAUTHORISED;
        }
        case 'incorrect-scope': {
          return HTTPResponses.FORBIDDEN;
        }
        case 'missing-identity-id': {
          return HTTPResponses.INVALID_REQUEST;
        }
        case 'success': {
          userId = resolution.userId as string;
          break;
        }
      }
    }

    const userSubscriptionIds = await getUserSubscriptionIds(userId);
    const subscriptionStatuses = await getSubscriptions(userSubscriptionIds);

    return { statusCode: 200, body: JSON.stringify(subscriptionStatuses) };
  } catch (error) {
    console.log(`Error retrieving user subscriptions: ${error}`);
    return HTTPResponses.INTERNAL_ERROR;
  }
}