generated from EyeSeeTea/dhis2-app-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #299 from EyeSeeTea/development
Release 1.6.18
- Loading branch information
Showing
29 changed files
with
313 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { D2Api, MetadataPick } from "@eyeseetea/d2-api/2.34"; | ||
import { FutureData } from "../../domain/entities/Future"; | ||
import { apiToFuture } from "../../utils/futures"; | ||
import { CountryRepository } from "../../domain/repositories/CountryRepository"; | ||
import { Country } from "../../domain/entities/Country"; | ||
|
||
export class CountryDefaultRepository implements CountryRepository { | ||
constructor(private api: D2Api) {} | ||
|
||
public getAll(): FutureData<Country[]> { | ||
return apiToFuture( | ||
this.api.models.organisationUnits.get({ | ||
fields: organisationUnitsFields, | ||
paging: false, | ||
level: 3, | ||
}) | ||
).map(response => { | ||
return this.buildOrgUnits(response.objects); | ||
}); | ||
} | ||
|
||
private buildOrgUnits(d2OrgUnits: D2OrgUnit[]): Country[] { | ||
return d2OrgUnits.map(d2OrgUnit => ({ | ||
id: d2OrgUnit.id, | ||
name: d2OrgUnit.name, | ||
shortName: d2OrgUnit.shortName, | ||
code: d2OrgUnit.code, | ||
})); | ||
} | ||
} | ||
|
||
const organisationUnitsFields = { | ||
id: true, | ||
name: true, | ||
shortName: true, | ||
code: true, | ||
description: { id: true, name: true }, | ||
geometry: true, | ||
organisationUnitGroups: { id: true, name: true }, | ||
} as const; | ||
|
||
type D2OrgUnit = MetadataPick<{ | ||
organisationUnits: { fields: typeof organisationUnitsFields }; | ||
}>["organisationUnits"][number]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export type Country = { | ||
id: string; | ||
name: string; | ||
shortName: string; | ||
code: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Country } from "../entities/Country"; | ||
import { FutureData } from "../entities/Future"; | ||
|
||
export interface CountryRepository { | ||
getAll(): FutureData<Country[]>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { UseCase } from "../../CompositionRoot"; | ||
import { Country } from "../entities/Country"; | ||
import { FutureData } from "../entities/Future"; | ||
import { CountryRepository } from "../repositories/CountryRepository"; | ||
|
||
export class GetAllCountriesUseCase implements UseCase { | ||
constructor(private countryRepository: CountryRepository) {} | ||
|
||
public execute(): FutureData<Country[]> { | ||
return this.countryRepository.getAll(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.