|
| 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 {} |
0 commit comments