diff --git a/src/main/java/com/nonononoki/alovoa/service/AdminService.java b/src/main/java/com/nonononoki/alovoa/service/AdminService.java index cff1d0ab..2b6e30ad 100644 --- a/src/main/java/com/nonononoki/alovoa/service/AdminService.java +++ b/src/main/java/com/nonononoki/alovoa/service/AdminService.java @@ -213,6 +213,10 @@ public void deleteAccount(AdminAccountDeleteDto dto) throws AlovoaException { User user = userRepo.findByEmail(dto.getEmail()); + if (user == null) { + throw new AlovoaException("user_not_found"); + } + if (user.isAdmin()) { throw new AlovoaException("cannot_delete_admin"); } @@ -226,8 +230,6 @@ public void deleteAccount(AdminAccountDeleteDto dto) throws AlovoaException { userRepo.delete(userRepo.findByEmail(user.getEmail())); userRepo.flush(); } - - throw new AlovoaException("user_not_found"); } private void checkRights() throws AlovoaException {