Skip to content

Commit 2a556f7

Browse files
committed
Report StepNotPlanned as an extraction problem instead of a thrown error
When extracting from progress upload. Mutations from UI to update progress steps will still throw errors.
1 parent 376833c commit 2a556f7

File tree

3 files changed

+55
-15
lines changed

3 files changed

+55
-15
lines changed

src/components/product-progress/handlers/extract-pnp-progress.handler.ts

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { mapOf } from '@seedcompany/common';
2+
import { oneLine } from 'common-tags';
23
import { EventsHandler, ILogger, Logger } from '~/core';
34
import { ReportType } from '../../periodic-report/dto';
45
import { PeriodicReportUploadedEvent } from '../../periodic-report/events';
56
import { ProductService } from '../../product';
6-
import { ProducibleType } from '../../product/dto';
7+
import { ProducibleType, ProductStep } from '../../product/dto';
78
import { isScriptureEqual } from '../../scripture';
89
import { ProgressReportVariantProgress as Progress } from '../dto';
910
import { ProductProgressService } from '../product-progress.service';
11+
import { StepNotPlannedException } from '../step-not-planned.exception';
1012
import { StepProgressExtractor } from '../step-progress-extractor.service';
1113

1214
@EventsHandler(PeriodicReportUploadedEvent)
@@ -62,7 +64,7 @@ export class ExtractPnpProgressHandler {
6264
if (row.story) {
6365
const productId = storyProducts.get(row.story);
6466
if (productId) {
65-
return { productId, steps };
67+
return { extracted: row, productId, steps };
6668
}
6769
}
6870

@@ -73,15 +75,19 @@ export class ExtractPnpProgressHandler {
7375
isScriptureEqual(ref.scriptureRanges, row.scripture),
7476
);
7577
if (exactScriptureMatch) {
76-
return { productId: exactScriptureMatch.id, steps };
78+
return { extracted: row, productId: exactScriptureMatch.id, steps };
7779
}
7880

7981
const unspecifiedScriptureMatch = scriptureProducts.find(
8082
(ref) =>
8183
ref.book === row.bookName && ref.totalVerses === row.totalVerses,
8284
);
8385
if (unspecifiedScriptureMatch) {
84-
return { productId: unspecifiedScriptureMatch.id, steps };
86+
return {
87+
extracted: row,
88+
productId: unspecifiedScriptureMatch.id,
89+
steps,
90+
};
8591
}
8692
}
8793

@@ -95,16 +101,48 @@ export class ExtractPnpProgressHandler {
95101

96102
// Update progress for report & product
97103
await Promise.all(
98-
updates.map(async (input) => {
99-
await this.progress.update(
100-
{
101-
...input,
102-
reportId: event.report.id,
103-
// TODO this seems fine for now as only this variant will upload PnPs.
104-
variant: Progress.FallbackVariant,
105-
},
106-
event.session,
107-
);
104+
updates.map(async ({ extracted, ...input }) => {
105+
try {
106+
await this.progress.update(
107+
{
108+
...input,
109+
reportId: event.report.id,
110+
// TODO this seems fine for now as only this variant will upload PnPs.
111+
variant: Progress.FallbackVariant,
112+
},
113+
event.session,
114+
);
115+
} catch (e) {
116+
if (
117+
!(
118+
e instanceof AggregateError &&
119+
e.message === 'Invalid Progress Input'
120+
)
121+
) {
122+
throw e;
123+
}
124+
for (const error of e.errors) {
125+
if (!(error instanceof StepNotPlannedException)) {
126+
continue;
127+
}
128+
const stepLabel = ProductStep.entry(error.step).label;
129+
// kinda. close enough, I think, we give the cell ref as well.
130+
const goalLabel = extracted.bookName ?? extracted.story;
131+
result.addProblem({
132+
severity: 'Error',
133+
groups: [
134+
'Step is not planned',
135+
`_${goalLabel}_ has progress reported on steps that have not been declared to be worked in this engagement`,
136+
`_${goalLabel}_ has not declared _${stepLabel}_ \`${extracted.cell.ref}\` as a step that will be worked in this engagement`,
137+
],
138+
message: oneLine`
139+
Please update the goal in CORD to mark this step as planned
140+
or upload an updated PnP file to the "Planning Spreadsheet" on the engagement page.
141+
`,
142+
source: extracted.cell,
143+
});
144+
}
145+
}
108146
}),
109147
);
110148
}

src/components/product-progress/product-progress.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export class ProductProgressService {
165165
return [];
166166
});
167167
if (errors.length > 0) {
168-
throw new AggregateError(errors);
168+
throw new AggregateError(errors, 'Invalid Progress Input');
169169
}
170170

171171
const progress = await this.repo.update(input);

src/components/product-progress/step-progress-extractor.service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type ExtractedRow = MergeExclusive<
3939
*/
4040
rowIndex: number;
4141
steps: ReadonlyArray<{ step: Step; completed?: number | null }>;
42+
cell: Cell<ProgressSheet>;
4243
};
4344

4445
@Injectable()
@@ -100,6 +101,7 @@ const parseProgressRow =
100101
rowIndex: rowIndex + 1,
101102
order: index + 1,
102103
steps,
104+
cell,
103105
};
104106

105107
if (sheet.isOBS()) {

0 commit comments

Comments
 (0)