All files / app/routes/api/group/group-id/member/get get-members-of-group-controller.ts

100% Statements 9/9
100% Branches 4/4
100% Functions 1/1
100% Lines 9/9

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 231x 1x                 1x   4x 4x   4x 2x 2x   2x      
import {BadRequestError} from '@app/errors';
import {MembershipService} from '@app/models';
import {RequestHandler} from 'express';
 
/**
 * Handles request to get all members of the specified group.
 * @param req   - Request
 * @param res   - Response
 * @param next  - Next
 */
export const getMembersOfGroupController: RequestHandler =
async (req, res, next) => {
  const user = req.user;
  const groupId = parseInt(req.params.groupId, 10);
 
  if (!isNaN(groupId) && user) {
    const members = await MembershipService.findAllForGroup(user, groupId);
    res.send({members});
  } else {
    throw new BadRequestError('Missing information');
  }
};