Skip to content

Commit

Permalink
Add filters & sorting for pnp extraction errors on Progress Reports (#…
Browse files Browse the repository at this point in the history
…3335)

Co-authored-by: Carson Full <carson_full@tsco.org>
  • Loading branch information
rdonigian and CarsonF authored Dec 17, 2024
1 parent 966b2db commit 64bcb4b
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/components/pnp/extraction-result/extraction-result.dto.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Field, InterfaceType, ObjectType } from '@nestjs/graphql';
import { Field, InputType, InterfaceType, ObjectType } from '@nestjs/graphql';
import { many, Many } from '@seedcompany/common';
import { stripIndent } from 'common-tags';
import { UUID } from 'node:crypto';
import { keys as keysOf } from 'ts-transformer-keys';
import { Merge } from 'type-fest';
import * as uuid from 'uuid';
import { EnumType, ID, IdField, makeEnum } from '~/common';
import { EnumType, ID, IdField, makeEnum, SecuredProps } from '~/common';
import { InlineMarkdownScalar } from '~/common/markdown.scalar';
import { Cell } from '~/common/xlsx.util';

Expand Down Expand Up @@ -118,8 +119,20 @@ export type StoredProblem = Pick<PnpProblem, 'id'> & {
context: { [x: string]: unknown };
};

@InputType()
export class PnpExtractionResultFilters {
@Field(() => Boolean, {
nullable: true,
description: 'Only extraction results containing errors',
})
readonly hasError?: boolean;
}

@InterfaceType()
export abstract class PnpExtractionResult {
static readonly Props = keysOf<PnpExtractionResult>();
static readonly SecuredProps = keysOf<SecuredProps<PnpExtractionResult>>();

constructor(private readonly fileVersionId: ID<'FileVersion'>) {}

readonly problems = new Map<ID, StoredProblem>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,22 @@ import { inArray, node, relation } from 'cypher-query-builder';
import { SetNonNullable } from 'type-fest';
import { ID, PublicOf } from '~/common';
import { CommonRepository } from '~/core/database';
import { apoc, collect, exp, merge, variable } from '~/core/database/query';
import {
apoc,
collect,
count,
defineSorters,
exp,
filter,
merge,
SortCol,
variable,
} from '~/core/database/query';
import {
PnpExtractionResult,
PnpExtractionResultFilters,
PnpProblemType,
PnpProblemSeverity as Severity,
StoredProblem,
} from './extraction-result.dto';
import { PnpExtractionResultRepository } from './pnp-extraction-result.edgedb.repository';
Expand Down Expand Up @@ -117,3 +129,25 @@ export class PnpExtractionResultNeo4jRepository
.run();
}
}

export const pnpExtractionResultFilters = filter.define(
() => PnpExtractionResultFilters,
{
hasError: filter.pathExists([
node('node'),
relation('out', '', 'problem'),
node('', { severity: Severity.Error }),
]),
},
);

export const pnpExtractionResultSorters = defineSorters(PnpExtractionResult, {
totalErrors: (query) =>
query
.match([
node('node'),
relation('out', 'problem', 'problem'),
node('type', { severity: Severity.Error }),
])
.return<SortCol>(count('problem').as('sortValue')),
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '~/common';
import { EngagementFilters } from '../../engagement/dto';
import { PeriodicReportListInput } from '../../periodic-report/dto';
import { PnpExtractionResultFilters } from '../../pnp/extraction-result';
import { ProgressSummaryFilters } from '../../progress-summary/dto';
import { ProgressReportStatus } from './progress-report-status.enum';
import { ProgressReport } from './progress-report.entity';
Expand All @@ -27,6 +28,9 @@ export abstract class ProgressReportFilters extends PickType(

@FilterField(() => EngagementFilters)
readonly engagement?: EngagementFilters & {};

@FilterField(() => PnpExtractionResultFilters)
readonly pnpExtractionResult?: PnpExtractionResultFilters & {};
}

@InputType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from '~/core/database/query';
import { engagementSorters } from '../engagement/engagement.repository';
import { MergePeriodicReports } from '../periodic-report/dto';
import { pnpExtractionResultSorters } from '../pnp/extraction-result/pnp-extraction-result.neo4j.repository';
import { SummaryPeriod } from '../progress-summary/dto';
import { progressSummarySorters } from '../progress-summary/progress-summary.repository';
import { ProgressReport, ProgressReportStatus as Status } from './dto';
Expand Down Expand Up @@ -50,6 +51,18 @@ export const progressReportExtrasSorters: DefinedSorters<
SortFieldOf<typeof ProgressReport>
> = defineSorters(ProgressReport, {
// eslint-disable-next-line @typescript-eslint/naming-convention
'pnpExtractionResult.*': (query, input) =>
query
.with('node as report')
.match([
node('report'),
relation('out', '', 'reportFileNode'),
node('file', 'File'),
relation('out', '', 'pnpExtractionResult'),
node('node', 'PnpExtractionResult'),
])
.apply(sortWith(pnpExtractionResultSorters, input)),
// eslint-disable-next-line @typescript-eslint/naming-convention
'engagement.*': (query, input) =>
query
.with('node as report')
Expand Down
10 changes: 10 additions & 0 deletions src/components/progress-report/progress-report.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from '~/core/database/query';
import { engagementFilters } from '../engagement/engagement.repository';
import { progressReportSorters } from '../periodic-report/periodic-report.repository';
import { pnpExtractionResultFilters } from '../pnp/extraction-result/pnp-extraction-result.neo4j.repository';
import { SummaryPeriod } from '../progress-summary/dto';
import { progressSummaryFilters } from '../progress-summary/progress-summary.repository';
import {
Expand Down Expand Up @@ -109,5 +110,14 @@ export const progressReportFilters = filter.define(
node('node', 'Engagement'),
]),
),
pnpExtractionResult: filter.sub(() => pnpExtractionResultFilters)((sub) =>
sub.match([
node('outer'),
relation('out', '', 'reportFileNode'),
node('file', 'File'),
relation('out', '', 'pnpExtractionResult'),
node('node', 'PnpExtractionResult'),
]),
),
},
);

0 comments on commit 64bcb4b

Please sign in to comment.