fix: prevent deletion of owner

This commit is contained in:
Julian Krauser 2025-01-24 09:20:08 +01:00
parent 3beeec38f9
commit ff651b7d8f

View file

@ -10,6 +10,7 @@ import MailHelper from "../../../helpers/mailHelper";
import { CLUB_NAME } from "../../../env.defaults";
import { UpdateUserPermissionsCommand } from "../../../command/user/user/userPermissionCommand";
import UserPermissionCommandHandler from "../../../command/user/user/userPermissionCommandHandler";
import BadRequestException from "../../../exceptions/badRequestException";
/**
* @description get All users
@ -137,7 +138,11 @@ export async function updateUserRoles(req: Request, res: Response): Promise<any>
export async function deleteUser(req: Request, res: Response): Promise<any> {
const id = parseInt(req.params.id);
let user = await UserService.getById(id);
let { mail, isOwner } = await UserService.getById(id);
if (isOwner) {
throw new BadRequestException("Owner cannot be deleted");
}
let deleteUser: DeleteUserCommand = {
id: id,
@ -147,7 +152,7 @@ export async function deleteUser(req: Request, res: Response): Promise<any> {
try {
// sendmail
await MailHelper.sendMail(
user.mail,
mail,
`Email Bestätigung für Mitglieder Admin-Portal von ${CLUB_NAME}`,
`Ihr Nutzerkonto des Adminportals wurde erfolgreich gelöscht.`
);