From c7314354e007547eff6861014a998287e3cb6efe Mon Sep 17 00:00:00 2001 From: manelcecs Date: Tue, 2 Apr 2024 13:32:57 +0200 Subject: [PATCH] Rewrite how 'sourceSystemID' is fetched It was fetched from a wrong table --- src/domain-services/flows/graphql/args.ts | 3 ++- ...-from-nested-flow-filters-strategy-impl.ts | 2 +- .../report-details/graphql/types.ts | 9 +++++++ .../report-details/report-detail-service.ts | 26 +++++++++++++------ 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/domain-services/flows/graphql/args.ts b/src/domain-services/flows/graphql/args.ts index abbafd80..659b3194 100644 --- a/src/domain-services/flows/graphql/args.ts +++ b/src/domain-services/flows/graphql/args.ts @@ -1,5 +1,6 @@ import { ArgsType, Field, InputType } from 'type-graphql'; import { PaginationArgs } from '../../../utils/graphql/pagination'; +import { type SystemID } from '../../report-details/graphql/types'; import { type FlowSortField } from './types'; @InputType() @@ -23,7 +24,7 @@ export class NestedFlowFilters { reporterRefCode: string | null; @Field(() => String, { nullable: true }) - sourceSystemID: string | null; + sourceSystemID: SystemID | null; @Field(() => Number, { nullable: true }) legacyID: number | null; 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 5a633684..4a1a8b77 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 @@ -39,7 +39,7 @@ export class GetFlowIdsFromNestedFlowFiltersStrategyImpl // Get the flowIDs using 'sourceSystemID' if (nestedFlowFilters?.sourceSystemID) { flowsSourceSystemId = - await this.reportDetailService.getUniqueFlowIDsFromReportDetailsBySourceID( + await this.reportDetailService.getUniqueFlowIDsFromExternalDataBySourceSystemID( models, nestedFlowFilters.sourceSystemID ); diff --git a/src/domain-services/report-details/graphql/types.ts b/src/domain-services/report-details/graphql/types.ts index 175f3c73..fff32fe2 100644 --- a/src/domain-services/report-details/graphql/types.ts +++ b/src/domain-services/report-details/graphql/types.ts @@ -36,3 +36,12 @@ export class ReportDetail extends BaseType { @Field(() => String, { nullable: true }) channel: string | null; } +export type SystemID = + | 'CERF' + | 'EDRIS' + | 'IATI' + | 'OCT' + | 'OCT-CERF' + | 'OCT-CBPF' + | 'OCT-OCHA' + | undefined; diff --git a/src/domain-services/report-details/report-detail-service.ts b/src/domain-services/report-details/report-detail-service.ts index 2e3975e0..ada77bbd 100644 --- a/src/domain-services/report-details/report-detail-service.ts +++ b/src/domain-services/report-details/report-detail-service.ts @@ -5,7 +5,7 @@ import { type InstanceDataOfModel } from '@unocha/hpc-api-core/src/db/util/raw-m import { createBrandedValue } from '@unocha/hpc-api-core/src/util/types'; import { Service } from 'typedi'; import { type UniqueFlowEntity } from '../flows/model'; -import { type ReportDetail } from './graphql/types'; +import { type ReportDetail, type SystemID } from './graphql/types'; @Service() export class ReportDetailService { async getReportDetailsForFlows( @@ -90,22 +90,23 @@ export class ReportDetailService { return flowIDs; } - async getUniqueFlowIDsFromReportDetailsBySourceID( + async getUniqueFlowIDsFromExternalDataBySourceSystemID( models: Database, - sourceID: string + systemID: SystemID ): Promise { - const reportDetails: Array> = - await models.reportDetail.find({ + const externalData: Array> = + await models.externalData.find({ where: { - sourceID: sourceID, + systemID: systemID, + refDirection: 'source', // Mandatory condition }, skipValidation: true, }); const flowIDs: UniqueFlowEntity[] = []; - for (const reportDetail of reportDetails) { - flowIDs.push(this.mapReportDetailToUniqueFlowEntity(reportDetail)); + for (const external of externalData) { + flowIDs.push(this.mapExternalDataToUniqueFlowEntity(external)); } return flowIDs; @@ -119,4 +120,13 @@ export class ReportDetailService { versionID: reportDetail.versionID, }; } + + private mapExternalDataToUniqueFlowEntity( + external: InstanceDataOfModel + ): UniqueFlowEntity { + return { + id: createBrandedValue(external.flowID), + versionID: external.versionID, + }; + } }