From 9fc55bbb647d911baf6800f67e6151a80799fba5 Mon Sep 17 00:00:00 2001 From: Manumartin95 Date: Fri, 15 Sep 2023 15:10:00 +0200 Subject: [PATCH 1/7] feat: update user repository with new props --- src/features/shared/user/domain/user-repository.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/features/shared/user/domain/user-repository.ts b/src/features/shared/user/domain/user-repository.ts index 3e6f2f74..07ebe79f 100644 --- a/src/features/shared/user/domain/user-repository.ts +++ b/src/features/shared/user/domain/user-repository.ts @@ -1,7 +1,9 @@ import { User } from './user' import { UserInfo } from './user-info' +import { Id } from '../../../../shared/types/id' export interface UserRepository { getUser(): Promise - getUsers(): Promise + + getUsers(ids?: Id[], active?: boolean): Promise } From b35ebb866c4532fc21d1bcbc9be59d26aacd9573 Mon Sep 17 00:00:00 2001 From: Manumartin95 Date: Mon, 18 Sep 2023 10:55:58 +0200 Subject: [PATCH 2/7] feat: add ids and active as query params in users query --- .../user/application/get-users-list-qry.test.ts | 2 +- .../shared/user/application/get-users-list-qry.ts | 12 +++++++++--- .../user/infrastructure/http-user-repository.ts | 7 +++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/features/shared/user/application/get-users-list-qry.test.ts b/src/features/shared/user/application/get-users-list-qry.test.ts index 9691f214..974f56eb 100644 --- a/src/features/shared/user/application/get-users-list-qry.test.ts +++ b/src/features/shared/user/application/get-users-list-qry.test.ts @@ -6,7 +6,7 @@ describe('GetUsersList', () => { it('should get the users list using the repository', async () => { const { userRepository, getUsersListQry } = setup() - await getUsersListQry.internalExecute() + await getUsersListQry.internalExecute({}) expect(userRepository.getUsers).toBeCalled() }) diff --git a/src/features/shared/user/application/get-users-list-qry.ts b/src/features/shared/user/application/get-users-list-qry.ts index 8e3d2e66..e4f93843 100644 --- a/src/features/shared/user/application/get-users-list-qry.ts +++ b/src/features/shared/user/application/get-users-list-qry.ts @@ -3,15 +3,21 @@ import { USER_REPOSITORY } from '../../../../shared/di/container-tokens' import { inject, singleton } from 'tsyringe' import type { UserRepository } from '../domain/user-repository' import { UserInfo } from '../domain/user-info' +import { Id } from '../../../../shared/types/id' + +interface GetUsersParams { + ids?: Id[] + active?: boolean +} @UseCaseKey('GetUsersListQry') @singleton() -export class GetUsersListQry extends Query { +export class GetUsersListQry extends Query { constructor(@inject(USER_REPOSITORY) private userRepository: UserRepository) { super() } - internalExecute(): Promise { - return this.userRepository.getUsers() + internalExecute(params: GetUsersParams): Promise { + return this.userRepository.getUsers(params?.ids, params?.active) } } diff --git a/src/features/shared/user/infrastructure/http-user-repository.ts b/src/features/shared/user/infrastructure/http-user-repository.ts index e9366417..065dcf4f 100644 --- a/src/features/shared/user/infrastructure/http-user-repository.ts +++ b/src/features/shared/user/infrastructure/http-user-repository.ts @@ -4,6 +4,7 @@ import { AnonymousUserError } from '../domain/anonymous-user-error' import { UserRepository } from '../domain/user-repository' import { User } from '../domain/user' import { UserInfo } from '../domain/user-info' +import { Id } from '../../../../shared/types/id' @singleton() export class HttpUserRepository implements UserRepository { @@ -24,9 +25,11 @@ export class HttpUserRepository implements UserRepository { } } - async getUsers(): Promise { + async getUsers(ids?: Id[], active?: boolean): Promise { try { - return await this.httpClient.get(HttpUserRepository.usersPath) + return await this.httpClient.get(HttpUserRepository.usersPath, { + params: { ids, active } + }) } catch (error) { if (error.response?.status === 404 || error.response?.status === 401) { throw new AnonymousUserError() From b7619933e95d533f16f345b63813d727f4d673c7 Mon Sep 17 00:00:00 2001 From: Manumartin95 Date: Mon, 18 Sep 2023 10:57:06 +0200 Subject: [PATCH 3/7] feat: update users query to filter with users from activity response --- .../activity/application/get-activities-by-filters-qry.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/features/binnacle/features/activity/application/get-activities-by-filters-qry.ts b/src/features/binnacle/features/activity/application/get-activities-by-filters-qry.ts index b41cc29f..cdab9c4d 100644 --- a/src/features/binnacle/features/activity/application/get-activities-by-filters-qry.ts +++ b/src/features/binnacle/features/activity/application/get-activities-by-filters-qry.ts @@ -34,13 +34,15 @@ export class GetActivitiesByFiltersQry extends Query a.projectRoleId) const uniqueProjectRoleIds = Array.from(new Set(projectRoleIds)) + const userIds = activitiesResponse.map((activity) => activity.userId) + const uniqueUserIds = Array.from(new Set(userIds)) const [projectRolesInformation, usersList] = await Promise.all([ this.searchProjectRolesQry.execute({ ids: uniqueProjectRoleIds, year: new Date(queryParams.startDate).getFullYear() }), - this.getUsersListQry.execute() + this.getUsersListQry.execute({ ids: uniqueUserIds }) ]) const activities = this.activitiesWithRoleInformation.addRoleInformationToActivities( From bf54e99d924792be0304ee974f54f68223328e6c Mon Sep 17 00:00:00 2001 From: Manumartin95 Date: Mon, 18 Sep 2023 10:57:36 +0200 Subject: [PATCH 4/7] feat: update user filter to only get active users --- .../components/activity-user-filter/activity-user-filter.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/features/binnacle/features/activity/ui/components/activity-filters/components/activity-user-filter/activity-user-filter.tsx b/src/features/binnacle/features/activity/ui/components/activity-filters/components/activity-user-filter/activity-user-filter.tsx index 0315e6eb..6aba44f9 100644 --- a/src/features/binnacle/features/activity/ui/components/activity-filters/components/activity-user-filter/activity-user-filter.tsx +++ b/src/features/binnacle/features/activity/ui/components/activity-filters/components/activity-user-filter/activity-user-filter.tsx @@ -14,7 +14,7 @@ interface Props { export const ActivityUserFilter: FC = (props) => { const { t } = useTranslation() const { control } = useForm() - const { isLoading, result: users } = useExecuteUseCaseOnMount(GetUsersListQry) + const { isLoading, result: users } = useExecuteUseCaseOnMount(GetUsersListQry, { active: true }) const handleChange = (user: UserInfo) => { props.onChange(user) From e3ac5dae86ba66c6c161fbc16023987bf2580a10 Mon Sep 17 00:00:00 2001 From: Manumartin95 Date: Mon, 18 Sep 2023 11:24:37 +0200 Subject: [PATCH 5/7] feat: update user request to use as param ids from projects and not everyone --- .../features/project/application/get-projects-list-qry.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/features/administration/features/project/application/get-projects-list-qry.ts b/src/features/administration/features/project/application/get-projects-list-qry.ts index 2b6ff9a8..adaee759 100644 --- a/src/features/administration/features/project/application/get-projects-list-qry.ts +++ b/src/features/administration/features/project/application/get-projects-list-qry.ts @@ -6,6 +6,7 @@ import { OrganizationWithStatus } from '../domain/organization-status' import { Project } from '../domain/project' import type { ProjectRepository } from '../domain/project-repository' import { ProjectsWithUserName } from '../domain/services/projects-with-user-name' +import { Id } from '../../../../../shared/types/id' @UseCaseKey('GetProjectsListQry') @InvalidateCache @@ -21,7 +22,9 @@ export class GetProjectsListQry extends Query async internalExecute(organizationStatus?: OrganizationWithStatus): Promise { const projects = await this.projectRepository.getProjects(organizationStatus) - const usersList = await this.getUsersListQry.execute() + const usersList = await this.getUsersListQry.execute({ + ids: projects.map((project) => project.blockedByUser).filter((id) => id !== null) as Id[] + }) return this.projectsWithUserName.addUserNameToProjects(projects, usersList) } } From 4b74bf0f40687423d547cd297fb094088278c746 Mon Sep 17 00:00:00 2001 From: Manumartin95 Date: Mon, 18 Sep 2023 11:35:34 +0200 Subject: [PATCH 6/7] test: update test with new params --- .../user/infrastructure/http-user-repository.test.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/features/shared/user/infrastructure/http-user-repository.test.ts b/src/features/shared/user/infrastructure/http-user-repository.test.ts index 030f0108..6cf00f4f 100644 --- a/src/features/shared/user/infrastructure/http-user-repository.test.ts +++ b/src/features/shared/user/infrastructure/http-user-repository.test.ts @@ -44,9 +44,14 @@ describe('UserRepository', () => { httpClient.get.mockResolvedValue(UserMother.userList()) - const result = await userRepository.getUsers() + const result = await userRepository.getUsers([1, 2], true) - expect(httpClient.get).toHaveBeenCalledWith('/api/user') + expect(httpClient.get).toHaveBeenCalledWith('/api/user', { + params: { + active: true, + ids: [1, 2] + } + }) expect(result).toEqual(UserMother.userList()) }) From 6b18aa70743136f865715c1cce3e2626e5a4cf4b Mon Sep 17 00:00:00 2001 From: Manumartin95 Date: Mon, 18 Sep 2023 12:11:55 +0200 Subject: [PATCH 7/7] test: update test with new params --- .../project/application/get-projects-list-qry.test.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/features/administration/features/project/application/get-projects-list-qry.test.ts b/src/features/administration/features/project/application/get-projects-list-qry.test.ts index ad2716ac..dcaac761 100644 --- a/src/features/administration/features/project/application/get-projects-list-qry.test.ts +++ b/src/features/administration/features/project/application/get-projects-list-qry.test.ts @@ -3,18 +3,24 @@ import { mock } from 'jest-mock-extended' import { ProjectRepository } from '../domain/project-repository' import { ProjectsWithUserName } from '../domain/services/projects-with-user-name' import { GetProjectsListQry } from './get-projects-list-qry' +import { ProjectMother } from '../domain/tests/project-mother' describe('GetProjectsListQry', () => { it('should get the project list', async () => { - const { getProjectsListQry, projectRepository } = setup() + const { getProjectsListQry, projectRepository, getUsersListQry } = setup() const organizationWithStatus = { organizationId: 1, open: true } + projectRepository.getProjects.mockResolvedValue( + ProjectMother.projectsFilteredByOrganizationDateIso() + ) + await getProjectsListQry.internalExecute(organizationWithStatus) expect(projectRepository.getProjects).toBeCalledWith(organizationWithStatus) + expect(getUsersListQry.execute).toHaveBeenCalledWith({ ids: [2, 1] }) }) })