Skip to content

Commit

Permalink
refactor: get usergroup by code in data repo
Browse files Browse the repository at this point in the history
  • Loading branch information
deeonwuli committed Nov 14, 2024
1 parent 8880da2 commit b4a4107
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 32 deletions.
4 changes: 0 additions & 4 deletions src/CompositionRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof getCompositionRoot>;

Expand Down Expand Up @@ -145,9 +144,6 @@ function getCompositionRoot(repositories: Repositories) {
charts: {
getCases: new GetChartConfigByTypeUseCase(repositories.chartConfigRepository),
},
userGroup: {
getByCode: new GetUserGroupByCodeUseCase(repositories.userGroupRepository),
},
};
}

Expand Down
9 changes: 6 additions & 3 deletions src/data/repositories/UserGroupD2Repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,27 @@ 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<UserGroup> {
getIncidentManagerUserGroupByCode(): FutureData<UserGroup> {
return apiToFuture(
this.api.metadata.get({
userGroups: {
fields: {
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);
}
}
2 changes: 1 addition & 1 deletion src/data/repositories/test/UserGroupTestRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { UserGroupRepository } from "../../../domain/repositories/UserGroupRepos
import { FutureData } from "../../api-futures";

export class UserGroupTestRepository implements UserGroupRepository {
getUserGroupByCode(_code: string): FutureData<UserGroup> {
getIncidentManagerUserGroupByCode(): FutureData<UserGroup> {
return Future.success({
id: "1",
});
Expand Down
2 changes: 1 addition & 1 deletion src/domain/repositories/UserGroupRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { FutureData } from "../../data/api-futures";
import { UserGroup } from "../entities/UserGroup";

export interface UserGroupRepository {
getUserGroupByCode(code: string): FutureData<UserGroup>;
getIncidentManagerUserGroupByCode(): FutureData<UserGroup>;
}
11 changes: 2 additions & 9 deletions src/domain/usecases/GetConfigurationsUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -14,20 +13,14 @@ export class GetConfigurationsUseCase {
private userGroupRepository: UserGroupRepository
) {}

public execute({
incidentManagerUserGroupCode,
}: {
incidentManagerUserGroupCode: Code;
}): FutureData<Configurations> {
public execute(): FutureData<Configurations> {
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,
Expand Down
12 changes: 0 additions & 12 deletions src/domain/usecases/GetUserGroupByCodeUseCase.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/webapp/pages/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand Down

0 comments on commit b4a4107

Please sign in to comment.