Skip to content

Commit

Permalink
Add channel property to ReportDetails
Browse files Browse the repository at this point in the history
Fix date format
Correct naming for method 'groupByFlowObjectType'
  • Loading branch information
manelcecs committed Nov 22, 2023
1 parent f8a7066 commit d638aa4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
20 changes: 13 additions & 7 deletions src/domain-services/flows/flow-search-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class FlowSearchService {
const plansFO: FlowObject[] = [];
const usageYearsFO: FlowObject[] = [];

this.mapFlowObjects(
this.groupByFlowObjectType(
flowObjects,
organizationsFO,
locationsFO,
Expand Down 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 Expand Up @@ -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') {
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;
}
20 changes: 19 additions & 1 deletion 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 @@ -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;
}
}
4 changes: 2 additions & 2 deletions src/domain-services/usage-years/usage-year-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
}
}

0 comments on commit d638aa4

Please sign in to comment.