Skip to content

Commit

Permalink
Add legacyID suport with models approach
Browse files Browse the repository at this point in the history
  • Loading branch information
manelcecs committed Jan 26, 2024
1 parent 315124a commit 596f40d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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[] =
Expand Down
24 changes: 24 additions & 0 deletions src/domain-services/legacy/legacy-service.ts
Original file line number Diff line number Diff line change
@@ -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<FlowId | null> {
const legacyEntry = await models.legacy.findOne({
where: {
legacyID: legacyId,
objectType: 'flow',
},
});

if (legacyEntry) {
return createBrandedValue(legacyEntry.objectID);
}
return null;
}
}

0 comments on commit 596f40d

Please sign in to comment.