From 549368ebc080ec659a1158d8128fd66916ae6c2c Mon Sep 17 00:00:00 2001 From: manelcecs Date: Tue, 21 Nov 2023 14:27:02 +0100 Subject: [PATCH] Add channel property to ReportDetails Fix date format --- .../flows/flow-search-service.ts | 8 +++++++- .../report-details/graphql/types.ts | 3 +++ .../report-details/report-detail-service.ts | 20 ++++++++++++++++++- .../usage-years/usage-year-service.ts | 4 ++-- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/domain-services/flows/flow-search-service.ts b/src/domain-services/flows/flow-search-service.ts index 896128b5..e6e82168 100644 --- a/src/domain-services/flows/flow-search-service.ts +++ b/src/domain-services/flows/flow-search-service.ts @@ -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 ); }) 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(), }; } }