All files / app/routes/api/group/group-id/member/user-id/kick kick-user-controller.ts

100% Statements 10/10
100% Branches 5/5
100% Functions 1/1
100% Lines 10/10

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  1x 1x               1x 11x 11x 11x   11x   8x 3x   3x      
import {RequestHandler} from 'express';
import {BadRequestError} from '@app/errors';
import {GroupService} from '@app/models';
 
/**
 * Controller for handling kick request for a user from a group.
 * @param req   - Request
 * @param res   - Response
 * @param next  - Next
 */
export const kickUserController: RequestHandler = async (req, res, next) => {
  const currentUser = req.user;
  const groupId = parseInt(req.params.groupId, 10);
  const userId = parseInt(req.params.userId, 10);
 
  if (typeof currentUser === 'object' && !isNaN(groupId) && !isNaN(userId)) {
    // Call to service
    const members = await GroupService.kickUser(currentUser, groupId, userId);
    res.send({members});
  } else {
    throw new BadRequestError();
  }
};