diff --git a/src/domain-services/flows/flow-search-service.ts b/src/domain-services/flows/flow-search-service.ts index 896128b5..238a8e8e 100644 --- a/src/domain-services/flows/flow-search-service.ts +++ b/src/domain-services/flows/flow-search-service.ts @@ -108,7 +108,7 @@ export class FlowSearchService { const plansFO: FlowObject[] = []; const usageYearsFO: FlowObject[] = []; - this.mapFlowObjects( + this.groupByFlowObjectType( flowObjects, organizationsFO, locationsFO, @@ -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( @@ -188,7 +194,7 @@ export class FlowSearchService { childIDs, parentIDs, externalReferences, - reportDetails, + reportDetailsWithChannel, parkedParentSource ); }) @@ -317,12 +323,12 @@ export class FlowSearchService { return conditionsMap; } - private mapFlowObjects( + private groupByFlowObjectType( flowObjects: FlowObject[], - organizationsFO: any[], - locationsFO: any[], - plansFO: any[], - usageYearsFO: any[] + organizationsFO: FlowObject[], + locationsFO: FlowObject[], + plansFO: FlowObject[], + usageYearsFO: FlowObject[] ) { for (const flowObject of flowObjects) { if (flowObject.objectType === 'organization') { diff --git a/src/domain-services/report-details/graphql/types.ts b/src/domain-services/report-details/graphql/types.ts index 3d4ddfa9..175f3c73 100644 --- a/src/domain-services/report-details/graphql/types.ts +++ b/src/domain-services/report-details/graphql/types.ts @@ -32,4 +32,7 @@ export class ReportDetail extends BaseType { @Field(() => Number, { nullable: true }) organizationID: number | null; + + @Field(() => String, { nullable: true }) + channel: string | null; } diff --git a/src/domain-services/report-details/report-detail-service.ts b/src/domain-services/report-details/report-detail-service.ts index b7ef5533..e702ddde 100644 --- a/src/domain-services/report-details/report-detail-service.ts +++ b/src/domain-services/report-details/report-detail-service.ts @@ -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 { @@ -58,13 +59,30 @@ export class ReportDetailService { versionID: reportDetail.versionID, contactInfo: reportDetail.contactInfo, source: reportDetail.source, - date: reportDetail.date, + date: reportDetail.date + ? new Date(reportDetail.date).toISOString() + : null, sourceID: reportDetail.sourceID, refCode: reportDetail.refCode, verified: reportDetail.verified, 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; + } } diff --git a/src/domain-services/usage-years/usage-year-service.ts b/src/domain-services/usage-years/usage-year-service.ts index 7a495460..d6463108 100644 --- a/src/domain-services/usage-years/usage-year-service.ts +++ b/src/domain-services/usage-years/usage-year-service.ts @@ -52,8 +52,8 @@ export class UsageYearService { return { year: usageYear.year, direction: refDirection, - createdAt: usageYear.createdAt, - updatedAt: usageYear.updatedAt, + createdAt: usageYear.createdAt.toISOString(), + updatedAt: usageYear.updatedAt.toISOString(), }; } }