Skip to content

Commit 3dd86da

Browse files
authored
feat: Changes for My Tasks Implementation (#1108)
* changes for my task serach implementation * Changes for My Tasks
1 parent 660eb1a commit 3dd86da

File tree

4 files changed

+73
-5
lines changed

4 files changed

+73
-5
lines changed

backend/cats/src/app/services/application/applicationSearch.service.spec.ts

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,68 @@ describe('ApplicationSearchService', () => {
8686
`ApplicationSearchService: searchParam: ${searchParam}, page: ${page}, pageSize: ${pageSize}, filter: ${filter}, sortBy: ${sortBy}, sortByDir: ${sortByDir}.`,
8787
);
8888
expect(loggerService.log).toHaveBeenNthCalledWith(
89-
2,
89+
3,
9090
'ApplicationSearchService: 1 applications found.',
9191
);
9292
});
9393

94+
it('should filter applications by MY_ASSIGNED filter with user email', async () => {
95+
const searchParam = 'test';
96+
const page = 1;
97+
const pageSize = 10;
98+
const filter = Filter.MY_ASSIGNED;
99+
const sortBy = SortByField.ID;
100+
const sortByDir = SortByDirection.ASC;
101+
const user = { email: 'test@example.com' };
102+
103+
const mockApplication = new Application();
104+
mockApplication.id = 1;
105+
mockApplication.siteId = 1;
106+
mockApplication.updatedDateTime = new Date();
107+
mockApplication.appParticipants = [];
108+
mockApplication.appPriorities = [];
109+
110+
const queryBuilderMock = {
111+
leftJoinAndSelect: jest.fn().mockReturnThis(),
112+
andWhere: jest.fn().mockReturnThis(),
113+
orWhere: jest.fn().mockReturnThis(),
114+
skip: jest.fn().mockReturnThis(),
115+
take: jest.fn().mockReturnThis(),
116+
orderBy: jest.fn().mockReturnThis(),
117+
getManyAndCount: jest.fn().mockResolvedValue([[mockApplication], 1]),
118+
};
119+
120+
jest
121+
.spyOn(repository, 'createQueryBuilder')
122+
.mockReturnValue(queryBuilderMock as any);
123+
124+
const result = await service.searchApplications(
125+
searchParam,
126+
page,
127+
pageSize,
128+
filter,
129+
sortBy,
130+
sortByDir,
131+
user,
132+
);
133+
134+
expect(result).toBeInstanceOf(ApplicationSearchResult);
135+
expect(result.applications.length).toBe(1);
136+
expect(result.count).toBe(1);
137+
138+
// Verify that the user email filter was applied
139+
expect(queryBuilderMock.andWhere).toHaveBeenCalledWith(
140+
'person.email = :email',
141+
{ email: 'test@example.com' },
142+
);
143+
144+
// Verify the user email log was called
145+
expect(loggerService.log).toHaveBeenNthCalledWith(
146+
2,
147+
'ApplicationSearchService: Logged in user email: test@example.com.',
148+
);
149+
});
150+
94151
it('should throw an error if search fails', async () => {
95152
jest.spyOn(repository, 'createQueryBuilder').mockReturnValue({
96153
leftJoinAndSelect: jest.fn().mockReturnThis(),

backend/cats/src/app/services/application/applicationSearch.service.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ export class ApplicationSearchService {
3030
this.loggerService.log(
3131
`ApplicationSearchService: searchParam: ${searchParam}, page: ${page}, pageSize: ${pageSize}, filter: ${filter}, sortBy: ${sortBy}, sortByDir: ${sortByDir}.`,
3232
);
33+
this.loggerService.log(
34+
`ApplicationSearchService: Logged in user email: ${
35+
user?.email || 'No email found'
36+
}.`,
37+
);
3338

3439
const result = new ApplicationSearchResult();
3540
if (page <= 0 || pageSize <= 0) {
@@ -86,10 +91,14 @@ export class ApplicationSearchService {
8691
}),
8792
);
8893

89-
if (filter && filter.toLowerCase() === Filter.ASSIGNED) {
94+
if (filter && filter.toLowerCase() === Filter.MY_ASSIGNED) {
9095
query.andWhere('person.email = :email', { email: user.email });
9196
}
9297

98+
if (filter && filter.toLowerCase() === Filter.ASSIGNED) {
99+
query.andWhere('appParticipant.personId IS NOT NULL');
100+
}
101+
93102
if (filter === Filter.UNASSIGNED) {
94103
query.andWhere('appParticipant.personId IS NULL');
95104
} else if (filter === Filter.COMPLETED) {

backend/cats/src/app/utilities/enums/application/filter.enum.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export enum Filter {
66
COMPLETED = 'completed',
77
OVERCAPACITY = 'overcapacity',
88
ASSIGNED = 'assigned',
9+
MY_ASSIGNED = 'my_assigned',
910
}
1011

1112
registerEnumType(Filter, {

cats-frontend/src/app/features/applications/search/Search.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const Search: React.FC<SearchProps> = ({ filterMyTasks = false }) => {
3333
applicationResultColumns(filterMyTasks),
3434
);
3535
const [filter, setFilter] = useState<Filter>(
36-
filterMyTasks === true ? Filter.Assigned : Filter.All,
36+
filterMyTasks === true ? Filter.MyAssigned : Filter.All,
3737
);
3838
const [page, setPage] = useState<number>(1);
3939
const [pageSize, setPageSize] = useState<number>(5);
@@ -49,7 +49,7 @@ const Search: React.FC<SearchProps> = ({ filterMyTasks = false }) => {
4949
searchTerm: '',
5050
page: 1,
5151
pageSize: 5,
52-
filter: filterMyTasks === true ? Filter.Assigned : Filter.All,
52+
filter: filterMyTasks === true ? Filter.MyAssigned : Filter.All,
5353
sortBy: ApplicationSortByField.Id,
5454
sortByDir: ApplicationSortByDirection.Asc,
5555
});
@@ -67,6 +67,7 @@ const Search: React.FC<SearchProps> = ({ filterMyTasks = false }) => {
6767
sortBy: searchParams.sortBy,
6868
sortByDir: searchParams.sortByDir,
6969
},
70+
fetchPolicy: 'network-only',
7071
});
7172

7273
useEffect(() => {
@@ -198,7 +199,7 @@ const Search: React.FC<SearchProps> = ({ filterMyTasks = false }) => {
198199
{
199200
label: 'Assigned to Me',
200201
value: Filter.Assigned,
201-
onClick: () => handleFilterChange(Filter.Assigned),
202+
onClick: () => handleFilterChange(Filter.MyAssigned),
202203
isSelected: filter === Filter.Assigned,
203204
},
204205
];

0 commit comments

Comments
 (0)