Skip to content

Commit fa9d276

Browse files
committed
Initialize extraction results & stub passing around
1 parent d87617e commit fa9d276

File tree

8 files changed

+46
-8
lines changed

8 files changed

+46
-8
lines changed

src/components/periodic-report/events/periodic-report-uploaded.event.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { LazyGetter as Once } from 'lazy-get-decorator';
12
import { Session } from '~/common';
23
import { Downloadable, FileNode } from '../../file/dto';
4+
import { PnpProgressExtractionResult } from '../../pnp/extraction-result';
35
import { PeriodicReport } from '../dto';
46

57
/**
@@ -11,4 +13,8 @@ export class PeriodicReportUploadedEvent {
1113
readonly file: Downloadable<FileNode>,
1214
readonly session: Session,
1315
) {}
16+
17+
@Once() get pnpResult() {
18+
return new PnpProgressExtractionResult();
19+
}
1420
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ export class ExtractPnpProgressHandler {
2323
return;
2424
}
2525

26+
const result = event.pnpResult;
27+
2628
// parse progress data from pnp spreadsheet
2729
let progressRows;
2830
try {
29-
progressRows = await this.extractor.extract(event.file);
31+
progressRows = await this.extractor.extract(event.file, result);
3032
} catch (e) {
3133
this.logger.warning(e.message, {
3234
name: event.file.name,

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
ProgressSheet,
1515
WrittenScripturePlanningSheet,
1616
} from '../pnp';
17+
import { PnpProgressExtractionResult } from '../pnp/extraction-result';
1718
import { ProductStep as Step } from '../product/dto';
1819
import { ScriptureRange } from '../scripture/dto';
1920
import { StepProgressInput } from './dto';
@@ -42,7 +43,10 @@ type ExtractedRow = MergeExclusive<
4243

4344
@Injectable()
4445
export class StepProgressExtractor {
45-
async extract(file: Downloadable<unknown>) {
46+
async extract(
47+
file: Downloadable<unknown>,
48+
result: PnpProgressExtractionResult,
49+
) {
4650
const pnp = await Pnp.fromDownloadable(file);
4751
const sheet = pnp.progress;
4852

src/components/product/handlers/extract-products-from-pnp.handler.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
EngagementUpdatedEvent,
55
} from '../../engagement/events';
66
import { FileService } from '../../file';
7+
import { PnpPlanningExtractionResult } from '../../pnp/extraction-result';
78
import { getAvailableSteps } from '../dto';
89
import { PnpProductSyncService } from '../pnp-product-sync.service';
910

@@ -39,10 +40,13 @@ export class ExtractProductsFromPnpHandler
3940
);
4041
const pnp = this.files.asDownloadable(fv);
4142

43+
const result = new PnpPlanningExtractionResult();
44+
4245
const actionableProductRows = await this.syncer.parse({
4346
engagementId: engagement.id,
4447
availableSteps,
4548
pnp,
49+
result,
4650
});
4751

4852
await this.syncer.save({

src/components/product/pnp-product-sync.service.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { DateTime } from 'luxon';
66
import { ID, Session } from '~/common';
77
import { ILogger, Logger } from '~/core';
88
import { Downloadable, FileVersion } from '../file/dto';
9+
import { PnpExtractionResult } from '../pnp/extraction-result';
910
import { StoryService } from '../story';
1011
import {
1112
CreateDerivativeScriptureProduct,
@@ -36,14 +37,16 @@ export class PnpProductSyncService {
3637
engagementId,
3738
availableSteps,
3839
pnp,
40+
result,
3941
}: {
4042
engagementId: ID<'LanguageEngagement'>;
4143
availableSteps: readonly ProductStep[];
4244
pnp: Downloadable<FileVersion>;
45+
result: PnpExtractionResult;
4346
}) {
4447
let productRows;
4548
try {
46-
productRows = await this.extractor.extract(pnp, availableSteps);
49+
productRows = await this.extractor.extract(pnp, availableSteps, result);
4750
} catch (e) {
4851
this.logger.warning(e.message, {
4952
id: pnp.id,
@@ -52,10 +55,15 @@ export class PnpProductSyncService {
5255
return [];
5356
}
5457
if (productRows.length === 0) {
58+
// TODO: PnP Extraction Problem
5559
return [];
5660
}
5761

58-
return await this.matchRowsToProductChanges(engagementId, productRows);
62+
return await this.matchRowsToProductChanges(
63+
engagementId,
64+
productRows,
65+
result,
66+
);
5967
}
6068

6169
/**
@@ -65,6 +73,7 @@ export class PnpProductSyncService {
6573
private async matchRowsToProductChanges(
6674
engagementId: ID<'LanguageEngagement'>,
6775
rows: readonly ExtractedRow[],
76+
result: PnpExtractionResult,
6877
) {
6978
const scriptureProducts = rows[0].bookName
7079
? await this.products.loadProductIdsForBookAndVerse(

src/components/product/product.extractor.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ import {
1717
stepPlanCompleteDate,
1818
WrittenScripturePlanningSheet,
1919
} from '../pnp';
20+
import { PnpPlanningExtractionResult } from '../pnp/extraction-result';
2021
import { ScriptureRange, UnspecifiedScripturePortion } from '../scripture/dto';
21-
import { ProductStep as Step } from './dto';
22+
import { ProductStep, ProductStep as Step } from './dto';
2223

2324
@Injectable()
2425
export class ProductExtractor {
2526
async extract(
2627
file: Downloadable<unknown>,
27-
availableSteps: readonly Step[],
28+
availableSteps: readonly ProductStep[],
29+
result: PnpPlanningExtractionResult,
2830
): Promise<readonly ExtractedRow[]> {
2931
const pnp = await Pnp.fromDownloadable(file);
3032
const sheet = pnp.planning;

src/components/progress-summary/handlers/extract-pnp-file-on-upload.handler.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export class ExtractPnpFileOnUploadHandler {
1818
return;
1919
}
2020

21+
const result = event.pnpResult;
22+
2123
this.logger.info('Extracting progress summary', {
2224
report: event.report.id,
2325
userId: event.session.userId,
@@ -26,7 +28,11 @@ export class ExtractPnpFileOnUploadHandler {
2628

2729
let extracted;
2830
try {
29-
extracted = await this.extractor.extract(event.file, event.report.start);
31+
extracted = await this.extractor.extract(
32+
event.file,
33+
event.report.start,
34+
result,
35+
);
3036
} catch (e) {
3137
this.logger.warning(e.message, {
3238
name: event.file.name,

src/components/progress-summary/progress-summary.extractor.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ import { CalendarDate, fiscalQuarter, fiscalYear } from '~/common';
55
import { Column, Row } from '~/common/xlsx.util';
66
import { Downloadable } from '../file/dto';
77
import { Pnp, ProgressSheet } from '../pnp';
8+
import { PnpProgressExtractionResult } from '../pnp/extraction-result';
89
import { ProgressSummary as Progress } from './dto';
910

1011
@Injectable()
1112
export class ProgressSummaryExtractor {
12-
async extract(file: Downloadable<unknown>, date: CalendarDate) {
13+
async extract(
14+
file: Downloadable<unknown>,
15+
date: CalendarDate,
16+
result: PnpProgressExtractionResult,
17+
) {
1318
const pnp = await Pnp.fromDownloadable(file);
1419
const sheet = pnp.progress;
1520

0 commit comments

Comments
 (0)