generated from EyeSeeTea/dhis2-app-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
25 changed files
with
731 additions
and
911 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
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,36 @@ | ||
import { FutureData } from "../../domain/entities/Future"; | ||
import { OrgUnit } from "../../domain/entities/OrgUnit"; | ||
import { Id } from "../../domain/entities/Ref"; | ||
import { OrgUnitRepository } from "../../domain/repositories/OrgUnitRepository"; | ||
import { D2Api } from "../../types/d2-api"; | ||
import { apiToFuture } from "../../utils/futures"; | ||
|
||
const orgUnitFields = { id: true, name: true, displayName: true, path: true, level: true }; | ||
|
||
export class OrgUnitD2Repository implements OrgUnitRepository { | ||
constructor(private api: D2Api) {} | ||
|
||
public getOrgUnitRoots(): FutureData<OrgUnit[]> { | ||
return apiToFuture( | ||
this.api.models.organisationUnits.get({ | ||
paging: false, | ||
filter: { level: { eq: "1" } }, | ||
fields: orgUnitFields, | ||
}) | ||
).map(orgUnits => { | ||
return orgUnits.objects; | ||
}); | ||
} | ||
|
||
public getOrgUnitsByIds(ids: Id[]): FutureData<OrgUnit[]> { | ||
return apiToFuture( | ||
this.api.models.organisationUnits.get({ | ||
paging: false, | ||
fields: orgUnitFields, | ||
filter: { id: { in: ids } }, | ||
}) | ||
).map(orgUnits => { | ||
return orgUnits.objects; | ||
}); | ||
} | ||
} |
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,22 @@ | ||
import _ from "lodash"; | ||
import { Id } from "./Ref"; | ||
|
||
export type OrgUnitPath = string; | ||
|
||
export interface OrgUnit { | ||
id: Id; | ||
path: OrgUnitPath; | ||
name: string; | ||
displayName: string; | ||
level: number; | ||
} | ||
|
||
const pathSeparator = "/"; | ||
|
||
export function getIdFromPath(path: OrgUnitPath): Id { | ||
return _.last(path.split(pathSeparator)) as Id; | ||
} | ||
|
||
export function getOrgUnitParentPath(path: OrgUnitPath) { | ||
return _(path).split(pathSeparator).initial().join(pathSeparator); | ||
} |
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,8 @@ | ||
import { FutureData } from "../entities/Future"; | ||
import { OrgUnit } from "../entities/OrgUnit"; | ||
import { Id } from "../entities/Ref"; | ||
|
||
export interface OrgUnitRepository { | ||
getOrgUnitRoots(): FutureData<OrgUnit[]>; | ||
getOrgUnitsByIds(ids: Id[]): FutureData<OrgUnit[]>; | ||
} |
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,10 @@ | ||
import { Id } from "../entities/Ref"; | ||
import { OrgUnitRepository } from "../repositories/OrgUnitRepository"; | ||
|
||
export class GetOrgUnitsByIdsUseCase { | ||
constructor(private orgUnitRepository: OrgUnitRepository) {} | ||
|
||
execute(ids: Id[]) { | ||
return this.orgUnitRepository.getOrgUnitsByIds(ids); | ||
} | ||
} |
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,9 @@ | ||
import { OrgUnitRepository } from "../repositories/OrgUnitRepository"; | ||
|
||
export class GetRootOrgUnitsUseCase { | ||
constructor(private orgUnitRepository: OrgUnitRepository) {} | ||
|
||
execute() { | ||
return this.orgUnitRepository.getOrgUnitRoots(); | ||
} | ||
} |
Oops, something went wrong.