From c4e2621fb903a2913a868914fcef73c5e4502d25 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 24 Oct 2024 20:21:27 +0200 Subject: [PATCH] Now deletes all company members when deleting a company --- src/main/java/com/MeetMate/company/CompanyService.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/MeetMate/company/CompanyService.java b/src/main/java/com/MeetMate/company/CompanyService.java index ec425cc..414a18e 100644 --- a/src/main/java/com/MeetMate/company/CompanyService.java +++ b/src/main/java/com/MeetMate/company/CompanyService.java @@ -86,6 +86,13 @@ public void deleteCompany(String token) { } catch (Throwable t) { throw new MongoTransactionException("Could not delete company owner"); } + + try { + for (Long memberId : company.getMemberIds()) + userRepository.deleteById(memberId); + } catch (Throwable t) { + throw new MongoTransactionException("Could not delete company members"); + } companyRepository.delete(company); }