Skip to content

Commit

Permalink
Rewrite how 'sourceSystemID' is fetched
Browse files Browse the repository at this point in the history
It was fetched from a wrong table
  • Loading branch information
manelcecs committed Apr 2, 2024
1 parent 3e14ef3 commit c731435
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/domain-services/flows/graphql/args.ts
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
9 changes: 9 additions & 0 deletions src/domain-services/report-details/graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
26 changes: 18 additions & 8 deletions src/domain-services/report-details/report-detail-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -90,22 +90,23 @@ export class ReportDetailService {
return flowIDs;
}

async getUniqueFlowIDsFromReportDetailsBySourceID(
async getUniqueFlowIDsFromExternalDataBySourceSystemID(
models: Database,
sourceID: string
systemID: SystemID
): Promise<UniqueFlowEntity[]> {
const reportDetails: Array<InstanceDataOfModel<Database['reportDetail']>> =
await models.reportDetail.find({
const externalData: Array<InstanceDataOfModel<Database['externalData']>> =
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;
Expand All @@ -119,4 +120,13 @@ export class ReportDetailService {
versionID: reportDetail.versionID,
};
}

private mapExternalDataToUniqueFlowEntity(
external: InstanceDataOfModel<Database['externalData']>
): UniqueFlowEntity {
return {
id: createBrandedValue(external.flowID),
versionID: external.versionID,
};
}
}

0 comments on commit c731435

Please sign in to comment.