Skip to content

Commit

Permalink
Add channel property to ReportDetails
Browse files Browse the repository at this point in the history
  • Loading branch information
manelcecs committed Nov 21, 2023
1 parent f8a7066 commit e41dc0e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/domain-services/flows/flow-search-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ export class FlowSearchService {
const externalReferences = externalReferencesMap.get(flow.id) ?? [];
const reportDetails = reportDetailsMap.get(flow.id) ?? [];

const reportDetailsWithChannel =
this.reportDetailService.addChannelToReportDetails(
reportDetails,
categories
);

let parkedParentSource: FlowParkedParentSource[] = [];
if (flow.activeStatus && flowLink.length > 0) {
parkedParentSource = await this.getParketParents(
Expand Down Expand Up @@ -188,7 +194,7 @@ export class FlowSearchService {
childIDs,
parentIDs,
externalReferences,
reportDetails,
reportDetailsWithChannel,
parkedParentSource
);
})
Expand Down
3 changes: 3 additions & 0 deletions src/domain-services/report-details/graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ export class ReportDetail extends BaseType {

@Field(() => Number, { nullable: true })
organizationID: number | null;

@Field(() => String, { nullable: true })
channel: string | null;
}
16 changes: 16 additions & 0 deletions src/domain-services/report-details/report-detail-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { type FlowId } from '@unocha/hpc-api-core/src/db/models/flow';
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 { Service } from 'typedi';
import { type Category } from '../categories/graphql/types';
import { type ReportDetail } from './graphql/types';
@Service()
export class ReportDetailService {
Expand Down Expand Up @@ -65,6 +66,21 @@ export class ReportDetailService {
createdAt: reportDetail.createdAt.toISOString(),
updatedAt: reportDetail.updatedAt.toISOString(),
organizationID: reportDetail.organizationID,
channel: null,
};
}

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;
}
}

0 comments on commit e41dc0e

Please sign in to comment.