Skip to content

Commit

Permalink
Add route and session storage changes
Browse files Browse the repository at this point in the history
  • Loading branch information
connorpgpmcelroy committed May 1, 2024
1 parent 0977518 commit 74dc565
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 72 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hmcts/rpx-xui-common-lib",
"version": "2.0.17",
"version": "2.0.17-node-store-caseworkers",
"engines": {
"node": ">=18.17.0"
},
Expand Down
2 changes: 1 addition & 1 deletion projects/exui-common-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hmcts/rpx-xui-common-lib",
"version": "2.0.17",
"version": "2.0.17-node-store-caseworkers",
"peerDependencies": {
"launchdarkly-js-client-sdk": "^2.15.2",
"ngx-pagination": "^3.2.1",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ describe('FindAPersonService', () => {
const service = new FindAPersonService(mockHttpService, mockSessionStorageService);
const searchOptions = { searchTerm: 'term', services: ['IA'], userRole: PersonRole.CASEWORKER };
service.findCaseworkers(searchOptions);
expect(mockHttpService.post).toHaveBeenCalledWith('/workallocation/retrieveCaseWorkersForServices', { fullServices: ['IA'] });
expect(mockHttpService.post).toHaveBeenCalledWith('/workallocation/caseworker/getUsersByServiceName', { services: ['IA'], term: 'term' });
});

it('should change caseworkers to people', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable, of } from 'rxjs';
import { map, tap } from 'rxjs/operators';
import {
getAllCaseworkersFromServices,
getSessionStorageKeyForServiceId,
setCaseworkers
} from '../../gov-ui/util/session-storage/session-storage-utils';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import {
Caseworker,
CaseworkersByService,
JudicialUserModel,
Person,
PersonRole,
Expand Down Expand Up @@ -50,36 +44,9 @@ export class FindAPersonService {
}
this.assignedUser = searchOptions.assignedUser ? searchOptions.assignedUser : null;
const fullServices = searchOptions.services;
const storedServices = [];
const newServices: string[] = [];
const storedCaseworkersByService: CaseworkersByService[] = [];
fullServices.forEach(serviceId => {
const serviceKey = getSessionStorageKeyForServiceId(serviceId);
if (this.sessionStorageService.getItem(serviceKey)) {
storedServices.push(serviceId);
storedCaseworkersByService.push({ service: serviceId, caseworkers: JSON.parse(this.sessionStorageService.getItem(serviceKey)) });
} else {
newServices.push(serviceId);
}
});
// if all services are stored then return the stored caseworkers by service
if (storedServices.length === fullServices.length) {
const storedCaseworkers = getAllCaseworkersFromServices(storedCaseworkersByService);
return of(this.searchInCaseworkers(storedCaseworkers, searchOptions));
}
// all serviceIds passed in as node layer getting used anyway and caseworkers also stored there
return this.http.post<CaseworkersByService[]>('/workallocation/retrieveCaseWorkersForServices', { fullServices }).pipe(
tap(caseworkersByService => {
caseworkersByService.forEach(caseworkerListByService => {
// for any new service, ensure that they are then stored in the session
if (newServices.includes(caseworkerListByService.service)) {
setCaseworkers(caseworkerListByService.service, caseworkerListByService.caseworkers, this.sessionStorageService);
}
});
}),
map(caseworkersByService => {
const givenCaseworkers = getAllCaseworkersFromServices(caseworkersByService);
return this.searchInCaseworkers(givenCaseworkers, searchOptions);
return this.http.post<Caseworker[]>('/workallocation/caseworker/getUsersByServiceName', {services: fullServices, term: searchOptions.searchTerm}).pipe(
map(caseworkers => {
return this.searchInCaseworkers(caseworkers, searchOptions);
})
);
}
Expand Down Expand Up @@ -112,11 +79,9 @@ export class FindAPersonService {
roleCategory = RoleCategory.CTSC;
}
}
const searchTerm = searchOptions && searchOptions.searchTerm ? searchOptions.searchTerm.toLowerCase() : '';
const people = caseworkers ? this.mapCaseworkers(caseworkers, roleCategory) : [];
const finalPeopleList = people.filter(person => person && person.name && person.name.toLowerCase().includes(searchTerm));
return searchOptions.userIncluded ? finalPeopleList.filter(person => person && person.id !== this.assignedUser)
: finalPeopleList.filter(person => person && person.id !== this.userId && person.id !== this.assignedUser);
return searchOptions.userIncluded ? people.filter(person => person && person.id !== this.assignedUser)
: people.filter(person => person && person.id !== this.userId && person.id !== this.assignedUser);
}

public searchJudicial(value: string, serviceId: string): Observable<JudicialUserModel[]> {
Expand Down

0 comments on commit 74dc565

Please sign in to comment.