Skip to content

Commit d87617e

Browse files
committed
Create shapes to hold pnp extraction result / problems
1 parent ed063d3 commit d87617e

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed

src/common/xlsx.util.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,15 @@ export class Cell<TSheet extends Sheet = Sheet> {
252252
: undefined;
253253
}
254254

255-
toString() {
255+
get fqn() {
256+
return `${this.sheet.name}!${this.ref}`;
257+
}
258+
get ref() {
256259
return `${this.column.a1}${this.row.a1}`;
257260
}
261+
toString() {
262+
return this.ref;
263+
}
258264
}
259265

260266
abstract class Rangable<TSheet extends Sheet = Sheet> {
@@ -301,9 +307,12 @@ abstract class Rangable<TSheet extends Sheet = Sheet> {
301307
);
302308
}
303309

304-
toString() {
310+
get ref() {
305311
return `${this.sheet.name}!${this.start.toString()}:${this.end.toString()}`;
306312
}
313+
toString() {
314+
return this.ref;
315+
}
307316
}
308317

309318
export class Range<TSheet extends Sheet = Sheet> extends Rangable<TSheet> {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { Field, InterfaceType, ObjectType } from '@nestjs/graphql';
2+
import { many, Many } from '@seedcompany/common';
3+
import { stripIndent } from 'common-tags';
4+
import { EnumType, makeEnum } from '~/common';
5+
import { InlineMarkdownScalar } from '~/common/markdown.scalar';
6+
import { Cell } from '~/common/xlsx.util';
7+
8+
export type PnpProblemSeverity = EnumType<typeof PnpProblemSeverity>;
9+
export const PnpProblemSeverity = makeEnum({
10+
name: 'PnpProblemSeverity',
11+
values: ['Error', 'Warning', 'Notice'],
12+
});
13+
14+
@ObjectType()
15+
export class PnpProblem {
16+
@Field(() => PnpProblemSeverity)
17+
readonly severity: PnpProblemSeverity;
18+
19+
@Field(() => InlineMarkdownScalar, {
20+
description: 'The message describing this specific problem',
21+
})
22+
readonly message: string;
23+
24+
@Field(() => String, {
25+
description: 'Sheet!A1',
26+
})
27+
readonly source: string;
28+
29+
@Field(() => [InlineMarkdownScalar], {
30+
description: stripIndent`
31+
Groupings for this problem.
32+
Order least specific to most.
33+
Formatted as human labels.
34+
`,
35+
})
36+
readonly groups: readonly string[];
37+
}
38+
39+
@InterfaceType()
40+
export abstract class PnpExtractionResult {
41+
@Field(() => [PnpProblem])
42+
readonly problems: PnpProblem[] = [];
43+
44+
addProblem(
45+
problem: Omit<PnpProblem, 'groups' | 'source'> & {
46+
groups?: Many<string>;
47+
source: Cell;
48+
},
49+
) {
50+
this.problems.push({
51+
...problem,
52+
groups: [problem.source.sheet.name, ...many(problem.groups ?? [])],
53+
source: problem.source.fqn,
54+
});
55+
}
56+
}
57+
@ObjectType({ implements: PnpExtractionResult })
58+
export class PnpPlanningExtractionResult extends PnpExtractionResult {}
59+
@ObjectType({ implements: PnpExtractionResult })
60+
export class PnpProgressExtractionResult extends PnpExtractionResult {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './extraction-result.dto';

0 commit comments

Comments
 (0)