diff --git a/src/components/pnp/extraction-result/planning-extraction-result-saver.ts b/src/components/pnp/extraction-result/planning-extraction-result-saver.ts new file mode 100644 index 0000000000..95cd640f29 --- /dev/null +++ b/src/components/pnp/extraction-result/planning-extraction-result-saver.ts @@ -0,0 +1,13 @@ +import { Injectable } from '@nestjs/common'; +import { ID } from '~/common'; +import { PnpExtractionResult } from './extraction-result.dto'; +import { PnpExtractionResultRepository } from './pnp-extraction-result.edgedb.repository'; + +@Injectable() +export class PlanningExtractionResultSaver { + constructor(private readonly repo: PnpExtractionResultRepository) {} + + async save(file: ID<'FileVersion'>, result: PnpExtractionResult) { + await this.repo.save(file, result); + } +} diff --git a/src/components/pnp/extraction-result/pnp-extraction-result-language-engagement-connection.resolver.ts b/src/components/pnp/extraction-result/pnp-extraction-result-language-engagement-connection.resolver.ts new file mode 100644 index 0000000000..5b25aa77af --- /dev/null +++ b/src/components/pnp/extraction-result/pnp-extraction-result-language-engagement-connection.resolver.ts @@ -0,0 +1,24 @@ +import { Parent, ResolveField, Resolver } from '@nestjs/graphql'; +import { Loader, LoaderOf } from '@seedcompany/data-loader'; +import { LanguageEngagement } from '../../engagement/dto'; +import { PnpPlanningExtractionResult } from './extraction-result.dto'; +import { PnpExtractionResultLoader } from './pnp-extraction-result.loader'; + +@Resolver(LanguageEngagement) +export class PnpExtractionResultLanguageEngagementConnectionResolver { + @ResolveField(() => PnpPlanningExtractionResult, { + nullable: true, + }) + async pnpExtractionResult( + @Parent() engagement: LanguageEngagement, + @Loader(() => PnpExtractionResultLoader) + loader: LoaderOf, + ): Promise { + const file = engagement.pnp.value; + if (!file) { + return null; + } + const { result } = await loader.load(file.id); + return result; + } +} diff --git a/src/components/pnp/extraction-result/pnp-extraction-result.module.ts b/src/components/pnp/extraction-result/pnp-extraction-result.module.ts index 8108dab7a0..0ab621f9c1 100644 --- a/src/components/pnp/extraction-result/pnp-extraction-result.module.ts +++ b/src/components/pnp/extraction-result/pnp-extraction-result.module.ts @@ -1,6 +1,8 @@ -import { Module } from '@nestjs/common'; +import { forwardRef, Module } from '@nestjs/common'; import { splitDb2 } from '~/core'; import { ProductModule } from '../../product/product.module'; +import { PlanningExtractionResultSaver } from './planning-extraction-result-saver'; +import { PnpExtractionResultLanguageEngagementConnectionResolver } from './pnp-extraction-result-language-engagement-connection.resolver'; import { PnpExtractionResultProgressReportConnectionResolver } from './pnp-extraction-result-progress-report-connection.resolver'; import { PnpExtractionResultRepository } from './pnp-extraction-result.edgedb.repository'; import { PnpExtractionResultLoader } from './pnp-extraction-result.loader'; @@ -8,15 +10,18 @@ import { PnpExtractionResultNeo4jRepository } from './pnp-extraction-result.neo4 import { SaveProgressExtractionResultHandler } from './save-progress-extraction-result.handler'; @Module({ - imports: [ProductModule], + imports: [forwardRef(() => ProductModule)], providers: [ + PnpExtractionResultLanguageEngagementConnectionResolver, PnpExtractionResultProgressReportConnectionResolver, PnpExtractionResultLoader, + PlanningExtractionResultSaver, SaveProgressExtractionResultHandler, splitDb2(PnpExtractionResultRepository, { edge: PnpExtractionResultRepository, neo4j: PnpExtractionResultNeo4jRepository, }), ], + exports: [PlanningExtractionResultSaver], }) export class PnpExtractionResultModule {} diff --git a/src/components/product/handlers/extract-products-from-pnp.handler.ts b/src/components/product/handlers/extract-products-from-pnp.handler.ts index 38dcf49b6c..8878692dbb 100644 --- a/src/components/product/handlers/extract-products-from-pnp.handler.ts +++ b/src/components/product/handlers/extract-products-from-pnp.handler.ts @@ -5,6 +5,7 @@ import { } from '../../engagement/events'; import { FileService } from '../../file'; import { PnpPlanningExtractionResult } from '../../pnp/extraction-result'; +import { PlanningExtractionResultSaver } from '../../pnp/extraction-result/planning-extraction-result-saver'; import { getAvailableSteps } from '../dto'; import { PnpProductSyncService } from '../pnp-product-sync.service'; @@ -17,6 +18,7 @@ export class ExtractProductsFromPnpHandler constructor( private readonly syncer: PnpProductSyncService, private readonly files: FileService, + private readonly planningExtractionResultSaver: PlanningExtractionResultSaver, ) {} async handle(event: SubscribedEvent): Promise { @@ -55,5 +57,7 @@ export class ExtractProductsFromPnpHandler actionableProductRows, session: event.session, }); + + await this.planningExtractionResultSaver.save(file.latestVersionId, result); } } diff --git a/src/components/product/product.module.ts b/src/components/product/product.module.ts index c2c1583129..de8e8fad15 100644 --- a/src/components/product/product.module.ts +++ b/src/components/product/product.module.ts @@ -1,6 +1,7 @@ import { forwardRef, Module } from '@nestjs/common'; import { AuthorizationModule } from '../authorization/authorization.module'; import { FileModule } from '../file/file.module'; +import { PnpExtractionResultModule } from '../pnp/extraction-result/pnp-extraction-result.module'; import { ScriptureModule } from '../scripture'; import { StoryModule } from '../story/story.module'; import * as handlers from './handlers'; @@ -20,6 +21,7 @@ import { ProductService } from './product.service'; ScriptureModule, FileModule, StoryModule, + PnpExtractionResultModule, ], providers: [ ProductResolver,