-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
validate org. units for country dataSet
- Loading branch information
Showing
17 changed files
with
195 additions
and
47 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,33 @@ | ||
import { WmrDataSet } from "../../domain/entities/wmr/entities/WmrDataSet"; | ||
import { WmrDataSetRepository } from "../../domain/entities/wmr/repositories/WmrDataSetRepository"; | ||
import { Instance } from "../../domain/instance/entities/Instance"; | ||
import { D2Api } from "../../types/d2-api"; | ||
import { getD2APiFromInstance } from "../../utils/d2-utils"; | ||
import { dataSetFields } from "./WmrSettingsD2Repository"; | ||
|
||
export class WmrDataSetD2Repository implements WmrDataSetRepository { | ||
private api: D2Api; | ||
constructor(private instance: Instance) { | ||
this.api = getD2APiFromInstance(this.instance); | ||
} | ||
|
||
async getById(id: string): Promise<WmrDataSet> { | ||
const response = await this.api.models.dataSets | ||
.get({ | ||
filter: { id: { eq: id } }, | ||
fields: { ...dataSetFields, organisationUnits: { id: true, displayName: true } }, | ||
}) | ||
.getData(); | ||
const dataSet = response.objects[0]; | ||
if (!dataSet) throw new Error(`Data set not found: ${id}`); | ||
return { | ||
id: dataSet.id, | ||
name: dataSet.displayName, | ||
dataElements: dataSet.dataSetElements.map(({ dataElement }) => ({ | ||
id: dataElement.id, | ||
name: dataElement.displayName, | ||
})), | ||
orgUnits: dataSet.organisationUnits.map(ou => ({ id: ou.id, name: ou.displayName })), | ||
}; | ||
} | ||
} |
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,27 @@ | ||
import _ from "lodash"; | ||
import { NamedRef } from "../../../common/entities/Ref"; | ||
import { Id } from "../../../common/entities/Schemas"; | ||
|
||
export type WmrDataSetAttrs = NamedRef & { dataElements: NamedRef[]; orgUnits: NamedRef[] }; | ||
|
||
export class WmrDataSet { | ||
public readonly id: Id; | ||
public readonly name: string; | ||
public readonly dataElements: NamedRef[]; | ||
public readonly orgUnits: NamedRef[]; | ||
constructor(data: WmrDataSetAttrs) { | ||
this.id = data.id; | ||
this.name = data.name; | ||
this.dataElements = data.dataElements; | ||
this.orgUnits = data.orgUnits; | ||
} | ||
|
||
static getOrgUnitsIds(dataSet: WmrDataSet): Id[] { | ||
return dataSet.orgUnits.map(ou => ou.id); | ||
} | ||
|
||
static getDifferenceOrgsUnits(dataSet: WmrDataSet, otherDataSet: WmrDataSet): NamedRef[] { | ||
const difference = _(dataSet.orgUnits).differenceBy(otherDataSet.orgUnits, "id").value(); | ||
return difference; | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
src/domain/entities/wmr/repositories/WmrDataSetRepository.ts
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,11 @@ | ||
import { Id } from "../../../common/entities/Schemas"; | ||
import { Instance } from "../../../instance/entities/Instance"; | ||
import { WmrDataSet } from "../entities/WmrDataSet"; | ||
|
||
export interface WmrDataSetRepositoryConstructor { | ||
new (instance: Instance): WmrDataSetRepository; | ||
} | ||
|
||
export interface WmrDataSetRepository { | ||
getById(id: Id): Promise<WmrDataSet>; | ||
} |
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 { Id } from "../../../common/entities/Schemas"; | ||
import { RepositoryFactory } from "../../../common/factories/RepositoryFactory"; | ||
import { Instance } from "../../../instance/entities/Instance"; | ||
import { WmrDataSet } from "../entities/WmrDataSet"; | ||
|
||
export class GetDataSetByIdUseCase { | ||
constructor(private repositoryFactory: RepositoryFactory, private localInstance: Instance) {} | ||
|
||
execute(id: Id): Promise<WmrDataSet> { | ||
return this.repositoryFactory.wmrDataSetRepository(this.localInstance).getById(id); | ||
} | ||
} |
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.