diff --git a/package.json b/package.json index d2566809..9916cff7 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "lint": "yarn lint-prettier && yarn lint-eslint" }, "dependencies": { - "@unocha/hpc-api-core": "github:UN-OCHA/hpc-api-core#e298382f38848370c6daa0ac86b2016eddbef356", + "@unocha/hpc-api-core": "github:UN-OCHA/hpc-api-core#242c7c8e88ee130695b987afc06589afd5408710", "apollo-server-hapi": "^3.12.0", "bunyan": "^1.8.15", "class-validator": "^0.14.0", diff --git a/src/domain-services/flows/strategy/impl/get-flowIds-flow-from-nested-flow-filters-strategy-impl.ts b/src/domain-services/flows/strategy/impl/get-flowIds-flow-from-nested-flow-filters-strategy-impl.ts index 154d7187..5a633684 100644 --- a/src/domain-services/flows/strategy/impl/get-flowIds-flow-from-nested-flow-filters-strategy-impl.ts +++ b/src/domain-services/flows/strategy/impl/get-flowIds-flow-from-nested-flow-filters-strategy-impl.ts @@ -1,4 +1,5 @@ import { Service } from 'typedi'; +import { LegacyService } from '../../../legacy/legacy-service'; import { ReportDetailService } from '../../../report-details/report-detail-service'; import { type UniqueFlowEntity } from '../../model'; import { @@ -12,7 +13,10 @@ import { intersectUniqueFlowEntities } from './utils'; export class GetFlowIdsFromNestedFlowFiltersStrategyImpl implements FlowIDSearchStrategy { - constructor(private readonly reportDetailService: ReportDetailService) {} + constructor( + private readonly reportDetailService: ReportDetailService, + private readonly legacyService: LegacyService + ) {} async search( args: FlowIdSearchStrategyArgs @@ -41,15 +45,20 @@ export class GetFlowIdsFromNestedFlowFiltersStrategyImpl ); } - // TODO: Get the flowIDs using 'legacyID' - // TODO: create model for that - // if(nestedFlowFilters?.legacyId) { - // flowsLegacyId = await this.flowService.getFlowIDsFromSourceSystemID( - // models, - // databaseConnection, - // nestedFlowFilters.sourceSystemId - // ); - // } + // Get the flowIDs using 'legacyID' + if (nestedFlowFilters?.legacyID) { + const flowID = await this.legacyService.getFlowIdFromLegacyId( + models, + nestedFlowFilters.legacyID + ); + + if (flowID) { + flowsLegacyId.push({ + id: flowID, + versionID: 1, + }); + } + } // Intersect the flowIDs from the nestedFlowFilters const flowIDsFromNestedFlowFilters: UniqueFlowEntity[] = diff --git a/src/domain-services/legacy/legacy-service.ts b/src/domain-services/legacy/legacy-service.ts new file mode 100644 index 00000000..060cf7fa --- /dev/null +++ b/src/domain-services/legacy/legacy-service.ts @@ -0,0 +1,24 @@ +import { type Database } from '@unocha/hpc-api-core/src/db'; +import { type FlowId } from '@unocha/hpc-api-core/src/db/models/flow'; +import { createBrandedValue } from '@unocha/hpc-api-core/src/util/types'; +import { Service } from 'typedi'; + +@Service() +export class LegacyService { + async getFlowIdFromLegacyId( + models: Database, + legacyId: number + ): Promise { + const legacyEntry = await models.legacy.findOne({ + where: { + legacyID: legacyId, + objectType: 'flow', + }, + }); + + if (legacyEntry) { + return createBrandedValue(legacyEntry.objectID); + } + return null; + } +}