All files / app/routes/api/group/group-id/member/user-id/admin/transer-ownership transfer-ownership-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 25 26  1x 1x   1x         11x 11x 11x   11x 8x           2x   3x      
import {RequestHandler} from 'express';
import {BadRequestError} from '@app/errors';
import {GroupService} from '@app/models';
 
export const transferOwnershipController: RequestHandler = async (
  req,
  res,
  next,
) => {
  const groupId = parseInt(req.params.groupId, 10);
  const userId = parseInt(req.params.userId, 10);
  const currentUser = req.user;
 
  if (currentUser && !isNaN(groupId) && !isNaN(userId)) {
    const group = await GroupService.transferOwnership(
        currentUser,
        groupId,
        userId,
    );
 
    res.send(group);
  } else {
    throw new BadRequestError();
  }
};