All files / app/routes/api/group/group-id/get get-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 23 24 25 26 27 28 29 30 311x     1x                               1x 9x 9x   9x 6x 4x   3x      
import {
  BadRequestError,
} from '@errors';
import {
  GroupService,
} from '@models';
import {RequestHandler} from 'express';
 
/**
 * Depending on who the requesting user is, respond with the group data.
 *
 * Only a user who is either invite to the group or is a member of the group
 * is authorized to view group data. If the user is not a member the user
 * will only receive partial data. If the user is a member the user will
 * receive all data of the group and a list of members.
 * @param req   - Request
 * @param res   - Response
 * @param next  - Next
 */
export const getGroupController: RequestHandler = async (req, res, next) => {
  const groupId = parseInt(req.params.groupId, 10);
  const user = req.user;
 
  if (!isNaN(groupId) && user) {
    const group = await GroupService.findById(user, groupId);
    res.send(group);
  } else {
    throw new BadRequestError('Missing information');
  }
};