From b4a41071d220e39716e37623865acd089c161121 Mon Sep 17 00:00:00 2001 From: Chukwudumebi Onwuli <37223065+deeonwuli@users.noreply.github.com> Date: Thu, 14 Nov 2024 08:49:15 +0100 Subject: [PATCH] refactor: get usergroup by code in data repo --- src/CompositionRoot.ts | 4 ---- src/data/repositories/UserGroupD2Repository.ts | 9 ++++++--- .../repositories/test/UserGroupTestRepository.ts | 2 +- src/domain/repositories/UserGroupRepository.ts | 2 +- src/domain/usecases/GetConfigurationsUseCase.ts | 11 ++--------- src/domain/usecases/GetUserGroupByCodeUseCase.ts | 12 ------------ src/webapp/pages/app/App.tsx | 3 +-- 7 files changed, 11 insertions(+), 32 deletions(-) delete mode 100644 src/domain/usecases/GetUserGroupByCodeUseCase.ts diff --git a/src/CompositionRoot.ts b/src/CompositionRoot.ts index 54f09cbf..f54db51d 100644 --- a/src/CompositionRoot.ts +++ b/src/CompositionRoot.ts @@ -71,7 +71,6 @@ import { CompleteEventTrackerUseCase } from "./domain/usecases/CompleteEventTrac import { UserGroupD2Repository } from "./data/repositories/UserGroupD2Repository"; import { UserGroupRepository } from "./domain/repositories/UserGroupRepository"; import { UserGroupTestRepository } from "./data/repositories/test/UserGroupTestRepository"; -import { GetUserGroupByCodeUseCase } from "./domain/usecases/GetUserGroupByCodeUseCase"; export type CompositionRoot = ReturnType; @@ -145,9 +144,6 @@ function getCompositionRoot(repositories: Repositories) { charts: { getCases: new GetChartConfigByTypeUseCase(repositories.chartConfigRepository), }, - userGroup: { - getByCode: new GetUserGroupByCodeUseCase(repositories.userGroupRepository), - }, }; } diff --git a/src/data/repositories/UserGroupD2Repository.ts b/src/data/repositories/UserGroupD2Repository.ts index 4f6caa35..a94b1718 100644 --- a/src/data/repositories/UserGroupD2Repository.ts +++ b/src/data/repositories/UserGroupD2Repository.ts @@ -3,11 +3,12 @@ import { UserGroupRepository } from "../../domain/repositories/UserGroupReposito import { apiToFuture, FutureData } from "../api-futures"; import { assertOrError } from "./utils/AssertOrError"; import { UserGroup } from "../../domain/entities/UserGroup"; +import { RTSL_ZEBRA_INCIDENTMANAGER } from "./TeamMemberD2Repository"; export class UserGroupD2Repository implements UserGroupRepository { constructor(private api: D2Api) {} - getUserGroupByCode(code: string): FutureData { + getIncidentManagerUserGroupByCode(): FutureData { return apiToFuture( this.api.metadata.get({ userGroups: { @@ -15,12 +16,14 @@ export class UserGroupD2Repository implements UserGroupRepository { id: true, }, filter: { - code: { eq: code }, + code: { eq: RTSL_ZEBRA_INCIDENTMANAGER }, }, }, }) ) - .flatMap(response => assertOrError(response.userGroups[0], `User group ${code}`)) + .flatMap(response => + assertOrError(response.userGroups[0], `User group ${RTSL_ZEBRA_INCIDENTMANAGER}`) + ) .map(userGroup => userGroup); } } diff --git a/src/data/repositories/test/UserGroupTestRepository.ts b/src/data/repositories/test/UserGroupTestRepository.ts index 22e4fc75..c0f579b9 100644 --- a/src/data/repositories/test/UserGroupTestRepository.ts +++ b/src/data/repositories/test/UserGroupTestRepository.ts @@ -4,7 +4,7 @@ import { UserGroupRepository } from "../../../domain/repositories/UserGroupRepos import { FutureData } from "../../api-futures"; export class UserGroupTestRepository implements UserGroupRepository { - getUserGroupByCode(_code: string): FutureData { + getIncidentManagerUserGroupByCode(): FutureData { return Future.success({ id: "1", }); diff --git a/src/domain/repositories/UserGroupRepository.ts b/src/domain/repositories/UserGroupRepository.ts index ac92a475..5693efce 100644 --- a/src/domain/repositories/UserGroupRepository.ts +++ b/src/domain/repositories/UserGroupRepository.ts @@ -2,5 +2,5 @@ import { FutureData } from "../../data/api-futures"; import { UserGroup } from "../entities/UserGroup"; export interface UserGroupRepository { - getUserGroupByCode(code: string): FutureData; + getIncidentManagerUserGroupByCode(): FutureData; } diff --git a/src/domain/usecases/GetConfigurationsUseCase.ts b/src/domain/usecases/GetConfigurationsUseCase.ts index c0e8f1a8..11791bb6 100644 --- a/src/domain/usecases/GetConfigurationsUseCase.ts +++ b/src/domain/usecases/GetConfigurationsUseCase.ts @@ -2,7 +2,6 @@ import { FutureData } from "../../data/api-futures"; import { Configurations, SelectableOptions } from "../entities/AppConfigurations"; import { Future } from "../entities/generic/Future"; import { TeamMember } from "../entities/incident-management-team/TeamMember"; -import { Code } from "../entities/Ref"; import { ConfigurationsRepository } from "../repositories/ConfigurationsRepository"; import { TeamMemberRepository } from "../repositories/TeamMemberRepository"; import { UserGroupRepository } from "../repositories/UserGroupRepository"; @@ -14,20 +13,14 @@ export class GetConfigurationsUseCase { private userGroupRepository: UserGroupRepository ) {} - public execute({ - incidentManagerUserGroupCode, - }: { - incidentManagerUserGroupCode: Code; - }): FutureData { + public execute(): FutureData { return Future.joinObj({ allTeamMembers: this.teamMemberRepository.getAll(), incidentResponseOfficers: this.teamMemberRepository.getIncidentResponseOfficers(), managers: this.teamMemberRepository.getIncidentManagers(), riskAssessors: this.teamMemberRepository.getRiskAssessors(), selectableOptionsResponse: this.configurationsRepository.getSelectableOptions(), - incidentManagerUserGroup: this.userGroupRepository.getUserGroupByCode( - incidentManagerUserGroupCode - ), + incidentManagerUserGroup: this.userGroupRepository.getIncidentManagerUserGroupByCode(), }).flatMap( ({ allTeamMembers, diff --git a/src/domain/usecases/GetUserGroupByCodeUseCase.ts b/src/domain/usecases/GetUserGroupByCodeUseCase.ts deleted file mode 100644 index 6a3d18cc..00000000 --- a/src/domain/usecases/GetUserGroupByCodeUseCase.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { FutureData } from "../../data/api-futures"; -import { Code } from "../entities/Ref"; -import { UserGroup } from "../entities/UserGroup"; -import { UserGroupRepository } from "../repositories/UserGroupRepository"; - -export class GetUserGroupByCodeUseCase { - constructor(private userGroupRepository: UserGroupRepository) {} - - public execute(code: Code): FutureData { - return this.userGroupRepository.getUserGroupByCode(code); - } -} diff --git a/src/webapp/pages/app/App.tsx b/src/webapp/pages/app/App.tsx index b7da6f9f..4d39c89a 100644 --- a/src/webapp/pages/app/App.tsx +++ b/src/webapp/pages/app/App.tsx @@ -18,7 +18,6 @@ import { D2Api } from "../../../types/d2-api"; import "./App.css"; import { CurrentEventTrackerContextProvider } from "../../contexts/CurrentEventTrackerProvider"; import { ExistingEventTrackerTypesProvider } from "../../contexts/ExistingEventTrackerTypes"; -import { RTSL_ZEBRA_INCIDENTMANAGER } from "../../../data/repositories/TeamMemberD2Repository"; export interface AppProps { compositionRoot: CompositionRoot; @@ -39,7 +38,7 @@ function App(props: AppProps) { const orgUnits = await compositionRoot.orgUnits.getAll.execute().toPromise(); const configurations = await compositionRoot.diseaseOutbreakEvent.getConfigurations - .execute({ incidentManagerUserGroupCode: RTSL_ZEBRA_INCIDENTMANAGER }) + .execute() .toPromise(); const isDev = process.env.NODE_ENV === "development";