All files / app/routes/api/user/invite/get-all get-all-invites-controller.ts

100% Statements 7/7
100% Branches 2/2
100% Functions 1/1
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26  1x 1x               1x               7x 1x   6x 5x      
import {RequestHandler} from 'express';
import {NotLoggedInError} from '@errors';
import {InviteService} from '@models';
 
/**
 * Controller for getting all invites of the currently logged in user.
 * @param req   - Request
 * @param res   - Response
 * @param _next  - Next
 */
export const getAllInvitesController: RequestHandler =
async (req, res, next) => {
  /*
   * Check if user is set on request.
   * This should never be the case as this route is protected by
   * the and not defined user should have been caught in an earlier
   * request handler.
   */
  if (req.user === undefined) {
    throw new NotLoggedInError();
  } else {
    const list = await InviteService.findAllForUser(req.user, req.user.id);
    res.send({invites: list});
  }
};