Skip to content

Commit 460210b

Browse files
committed
Only fetch CRM organisations
1 parent 0872c64 commit 460210b

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

server/src/main/java/invite/crm/CRMController.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -376,12 +376,14 @@ public ResponseEntity<String> remove(@RequestBody RemoveRoles removeRoles) {
376376
@SecurityRequirement(name = API_HEADER_SCHEME_NAME)
377377
@PreAuthorize("hasRole('CRM')")
378378
public ResponseEntity<List<CRMOrganisation>> organisations() {
379-
List<Organisation> organisations = organisationRepository.findAll();
380-
List<CRMOrganisation> crmOrganisations = organisations.stream().map(organisation -> new CRMOrganisation(
381-
organisation.getCrmOrganisationId(),
382-
organisation.getCrmOrganisationAbbrevation(),
383-
organisation.getCrmOrganisationName()
384-
)).toList();
379+
List<Organisation> organisations = organisationRepository.findByCrmOrganisationIdIsNotNull();
380+
List<CRMOrganisation> crmOrganisations = organisations.stream()
381+
.map(organisation -> new CRMOrganisation(
382+
organisation.getCrmOrganisationId(),
383+
organisation.getCrmOrganisationAbbrevation(),
384+
organisation.getCrmOrganisationName()
385+
))
386+
.toList();
385387
return ResponseEntity.ok(crmOrganisations);
386388
}
387389

@@ -408,7 +410,7 @@ public ResponseEntity<String> send(@RequestBody SendInvitation sendInvitation) {
408410
}
409411

410412
Organisation organisation = organisationRepository.findByCrmOrganisationId(sendInvitation.crmOrganisationId())
411-
.orElseThrow(() -> new NotFoundException("Organisation not found: "+sendInvitation.crmOrganisationId()));
413+
.orElseThrow(() -> new NotFoundException("Organisation not found: " + sendInvitation.crmOrganisationId()));
412414
CRMContact crmContact = new CRMContact();
413415
crmContact.setEmail(sendInvitation.email());
414416
crmContact.setRoles(sendInvitation.roles());

server/src/main/java/invite/repository/OrganisationRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@
1919
public interface OrganisationRepository extends JpaRepository<Organisation, Long> {
2020

2121
Optional<Organisation> findByCrmOrganisationId(String crmOrganisationId);
22+
23+
List<Organisation> findByCrmOrganisationIdIsNotNull();
2224
}

0 commit comments

Comments
 (0)