Skip to content

Commit

Permalink
chore: rename variables, add function return types
Browse files Browse the repository at this point in the history
  • Loading branch information
deeonwuli committed Aug 20, 2024
1 parent f0d84ac commit 9a45ed1
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/CompositionRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { OrgUnitTestRepository } from "./data/repositories/test/OrgUnitTestRepos
import { GetAllDiseaseOutbreaksUseCase } from "./domain/usecases/GetAllDiseaseOutbreaksUseCase";
import { SaveDiseaseOutbreakUseCase } from "./domain/usecases/SaveDiseaseOutbreakUseCase";
import { GetDiseaseOutbreakWithOptionsUseCase } from "./domain/usecases/GetDiseaseOutbreakWithOptionsUseCase";
import { MapDiseaseOutbreakToAlertUseCase } from "./domain/usecases/MapDiseaseOutbreakToAlertsUseCase";
import { MapDiseaseOutbreakToAlertsUseCase } from "./domain/usecases/MapDiseaseOutbreakToAlertsUseCase";
import { AlertRepository } from "./domain/repositories/AlertRepository";
import { AlertTestRepository } from "./data/repositories/test/AlertTestRepository";

Expand All @@ -45,7 +45,7 @@ function getCompositionRoot(repositories: Repositories) {
getWithOptions: new GetDiseaseOutbreakWithOptionsUseCase(repositories),
getAll: new GetAllDiseaseOutbreaksUseCase(repositories.diseaseOutbreakEventRepository),
save: new SaveDiseaseOutbreakUseCase(repositories.diseaseOutbreakEventRepository),
mapDiseaseOutbreakEventToAlert: new MapDiseaseOutbreakToAlertUseCase(
mapDiseaseOutbreakEventToAlerts: new MapDiseaseOutbreakToAlertsUseCase(
repositories.alertRepository
),
},
Expand Down
24 changes: 13 additions & 11 deletions src/data/repositories/AlertD2Repository.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { D2Api } from "@eyeseetea/d2-api/2.36";
import { apiToFuture, FutureData } from "../api-futures";
import {
RTSL_ZEBRA_ALERTS_EVENT_ID_TEA_ID,
RTSL_ZEBRA_ALERTS_NATIONAL_DISEASE_OUTBREAK_EVENT_ID_TEA_ID,
RTSL_ZEBRA_ALERTS_PROGRAM_ID,
RTSL_ZEBRA_ORG_UNIT_ID,
} from "./consts/DiseaseOutbreakConstants";
Expand All @@ -21,22 +21,22 @@ export class AlertD2Repository implements AlertRepository {
const { eventId, filter } = alertOptions;

return this.getTrackedEntitiesByTEACode(filter).flatMap(response => {
const trackedEntitiesToPost = response.map(trackedEntity => ({
const alertsToMap = response.map(trackedEntity => ({
...trackedEntity,
attributes: [
{
attribute: RTSL_ZEBRA_ALERTS_EVENT_ID_TEA_ID,
attribute: RTSL_ZEBRA_ALERTS_NATIONAL_DISEASE_OUTBREAK_EVENT_ID_TEA_ID,
value: eventId,
},
],
}));

if (trackedEntitiesToPost.length === 0) return Future.success(undefined);
if (alertsToMap.length === 0) return Future.success(undefined);

return apiToFuture(
this.api.tracker.post(
{ importStrategy: "UPDATE" },
{ trackedEntities: trackedEntitiesToPost }
{ trackedEntities: alertsToMap }
)
).map(saveResponse => {
if (saveResponse.status === "ERROR")
Expand All @@ -45,7 +45,10 @@ export class AlertD2Repository implements AlertRepository {
});
}

private async getTrackedEntitiesByTEACodeAsync(filter: { id: Id; value: string }) {
private async getTrackedEntitiesByTEACodeAsync(filter: {
id: Id;
value: string;
}): Promise<D2TrackerTrackedEntity[]> {
const d2TrackerTrackedEntities: D2TrackerTrackedEntity[] = [];

const pageSize = 250;
Expand All @@ -72,10 +75,6 @@ export class AlertD2Repository implements AlertRepository {
})
.getData();

if (!result.total) {
throw new Error("No tracked entities found");
}

d2TrackerTrackedEntities.push(...result.instances);

page++;
Expand All @@ -86,7 +85,10 @@ export class AlertD2Repository implements AlertRepository {
}
}

private getTrackedEntitiesByTEACode(filter: { id: Id; value: string }) {
private getTrackedEntitiesByTEACode(filter: {
id: Id;
value: string;
}): FutureData<D2TrackerTrackedEntity[]> {
return Future.fromPromise(this.getTrackedEntitiesByTEACodeAsync(filter));
}
}
2 changes: 1 addition & 1 deletion src/data/repositories/consts/DiseaseOutbreakConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const RTSL_ZEBRA_ORG_UNIT_ID = "PS5JpkoHHio";
export const RTSL_ZEBRA_TRACKED_ENTITY_TYPE_ID = "lIzNjLOUAKA";

export const RTSL_ZEBRA_ALERTS_PROGRAM_ID = "MQtbs8UkBxy";
export const RTSL_ZEBRA_ALERTS_EVENT_ID_TEA_ID = "Pq1drzz2HJk";
export const RTSL_ZEBRA_ALERTS_NATIONAL_DISEASE_OUTBREAK_EVENT_ID_TEA_ID = "Pq1drzz2HJk";
export const RTSL_ZEBRA_ALERTS_DISEASE_TEA_ID = "agsVaIpit4S";
export const RTSL_ZEBRA_ALERTS_EVENT_TYPE_TEA_ID = "ydsfY6zyvt7";

Expand Down
6 changes: 4 additions & 2 deletions src/domain/usecases/MapDiseaseOutbreakToAlertsUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import {
RTSL_ZEBRA_ALERTS_EVENT_TYPE_TEA_ID,
} from "../../data/repositories/consts/DiseaseOutbreakConstants";

export class MapDiseaseOutbreakToAlertUseCase {
const incidentDataSourceCode = "IBS";

export class MapDiseaseOutbreakToAlertsUseCase {
constructor(private alertRepository: AlertRepository) {}

public execute(
Expand All @@ -24,7 +26,7 @@ export class MapDiseaseOutbreakToAlertUseCase {
return Future.error(new Error("Disease Outbreak Event Id is required"));

const filter =
dataSourceCode === "IBS"
dataSourceCode === incidentDataSourceCode
? { id: RTSL_ZEBRA_ALERTS_DISEASE_TEA_ID, value: suspectedDiseaseCode }
: { id: RTSL_ZEBRA_ALERTS_EVENT_TYPE_TEA_ID, value: hazardTypeCode };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export function useDiseaseOutbreakEventForm(diseaseOutbreakEventId?: Id): State
diseaseOutbreakEventId => {
setIsSaved(true);

compositionRoot.diseaseOutbreakEvent.mapDiseaseOutbreakEventToAlert
compositionRoot.diseaseOutbreakEvent.mapDiseaseOutbreakEventToAlerts
.execute(diseaseOutbreakEventId, diseaseOutbreakEventData)
.run(
() => {
Expand All @@ -157,13 +157,7 @@ export function useDiseaseOutbreakEventForm(diseaseOutbreakEventId?: Id): State
setIsSaved(false);
}
);
}, [
compositionRoot.diseaseOutbreakEvent.mapDiseaseOutbreakEventToAlert,
compositionRoot.diseaseOutbreakEvent.save,
currentUser.username,
diseaseOutbreakEventWithOptions,
formState,
]);
}, [compositionRoot, currentUser.username, diseaseOutbreakEventWithOptions, formState]);

const onCancelForm = useCallback(() => {
goTo(RouteName.DASHBOARD);
Expand Down

0 comments on commit 9a45ed1

Please sign in to comment.