Skip to content

Commit

Permalink
Proper usage of nested flow properties filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
manelcecs committed Jan 25, 2024
1 parent 2ea19b3 commit 61fc155
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 39 deletions.
12 changes: 6 additions & 6 deletions src/domain-services/flows/graphql/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ export class SearchFlowsFilters {

@InputType()
export class NestedFlowFilters {
@Field(() => [String], { nullable: true })
reporterReferenceCodes: string[] | null;
@Field(() => String, { nullable: true })
reporterRefCode: string | null;

@Field(() => [String], { nullable: true })
sourceIDs: string[] | null;
@Field(() => String, { nullable: true })
sourceSystemID: string | null;

@Field(() => [Number], { nullable: true })
legacyIDs: number[] | null;
@Field(() => Number, { nullable: true })
legacyID: number | null;
}

@InputType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,25 @@ export class GetFlowIdsFromNestedFlowFiltersStrategyImpl
const flowsLegacyId: UniqueFlowEntity[] = [];

// Get the flowIDs using 'reporterReferenceCode'
if (
nestedFlowFilters?.reporterReferenceCodes &&
nestedFlowFilters?.reporterReferenceCodes.length > 0
) {
if (nestedFlowFilters?.reporterRefCode) {
flowsReporterReferenceCode =
await this.reportDetailService.getUniqueFlowIDsFromReportDetailsByReporterReferenceCode(
models,
nestedFlowFilters.reporterReferenceCodes
nestedFlowFilters.reporterRefCode
);
}

// Get the flowIDs using 'sourceSystemID'
if (
nestedFlowFilters?.sourceIDs &&
nestedFlowFilters?.sourceIDs.length > 0
) {
if (nestedFlowFilters?.sourceSystemID) {
flowsSourceSystemId =
await this.reportDetailService.getUniqueFlowIDsFromReportDetailsBySourceID(
models,
nestedFlowFilters.sourceIDs
nestedFlowFilters.sourceSystemID
);
}

// TODO: Get the flowIDs using 'legacyID'
// TODO: create model for that
// if(nestedFlowFilters?.legacyId) {
// flowsLegacyId = await this.flowService.getFlowIDsFromSourceSystemID(
// models,
Expand Down
27 changes: 4 additions & 23 deletions src/domain-services/report-details/report-detail-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Op } from '@unocha/hpc-api-core/src/db/util/conditions';
import { type InstanceDataOfModel } from '@unocha/hpc-api-core/src/db/util/raw-model';
import { createBrandedValue } from '@unocha/hpc-api-core/src/util/types';
import { Service } from 'typedi';
import { type Category } from '../categories/graphql/types';
import { type UniqueFlowEntity } from '../flows/model';
import { type ReportDetail } from './graphql/types';
@Service()
Expand Down Expand Up @@ -70,30 +69,14 @@ export class ReportDetailService {
};
}

addChannelToReportDetails(
reportDetails: ReportDetail[],
categories: Category[]
) {
for (const reportDetail of reportDetails) {
const category = categories.find((cat) => cat.group === 'reportChannel');

if (category) {
reportDetail.channel = category.name;
}
}
return reportDetails;
}

async getUniqueFlowIDsFromReportDetailsByReporterReferenceCode(
models: Database,
reporterReferenceCodes: string[]
reporterRefCode: string
): Promise<UniqueFlowEntity[]> {
const reportDetails: Array<InstanceDataOfModel<Database['reportDetail']>> =
await models.reportDetail.find({
where: {
refCode: {
[Op.IN]: reporterReferenceCodes,
},
refCode: reporterRefCode,
},
skipValidation: true,
});
Expand All @@ -109,14 +92,12 @@ export class ReportDetailService {

async getUniqueFlowIDsFromReportDetailsBySourceID(
models: Database,
sourceIDs: string[]
sourceID: string
): Promise<UniqueFlowEntity[]> {
const reportDetails: Array<InstanceDataOfModel<Database['reportDetail']>> =
await models.reportDetail.find({
where: {
sourceID: {
[Op.IN]: sourceIDs,
},
sourceID: sourceID,
},
skipValidation: true,
});
Expand Down

0 comments on commit 61fc155

Please sign in to comment.