transfer Ownership

This commit is contained in:
Julian Krauser 2024-11-21 15:58:47 +01:00
parent f87c7b4a7c
commit ea227433e6
4 changed files with 75 additions and 3 deletions

View file

@ -5,8 +5,9 @@ import InternalException from "../exceptions/internalException";
import { CLUB_NAME } from "../env.defaults";
import UserService from "../service/userService";
import UserFactory from "../factory/admin/user";
import { UpdateUserCommand } from "../command/userCommand";
import { TransferUserOwnerCommand, UpdateUserCommand } from "../command/userCommand";
import UserCommandHandler from "../command/userCommandHandler";
import ForbiddenRequestException from "../exceptions/forbiddenRequestException";
/**
* @description get my by id
@ -70,6 +71,30 @@ export async function verifyMyTotp(req: Request, res: Response): Promise<any> {
res.sendStatus(204);
}
/**
* @description transferOwnership
* @param req {Request} Express req object
* @param res {Response} Express res object
* @returns {Promise<*>}
*/
export async function transferOwnership(req: Request, res: Response): Promise<any> {
const userId = parseInt(req.userId);
let toId = req.body.toId;
let { isOwner } = await UserService.getById(userId);
if (!isOwner) {
throw new ForbiddenRequestException("Action only allowed to owner.");
}
let transfer: TransferUserOwnerCommand = {
toId: toId,
fromId: userId,
};
await UserCommandHandler.transferOwnership(transfer);
res.sendStatus(204);
}
/**
* @description update my data
* @param req {Request} Express req object