Skip to content

Commit

Permalink
Pnp planning persist (#3334)
Browse files Browse the repository at this point in the history
Co-authored-by: Carson Full <[email protected]>
  • Loading branch information
atGit2021 and CarsonF authored Dec 5, 2024
1 parent 9a12d10 commit 3b97014
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<PnpExtractionResultLoader>,
): Promise<PnpPlanningExtractionResult | null> {
const file = engagement.pnp.value;
if (!file) {
return null;
}
const { result } = await loader.load(file.id);
return result;
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
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';
import { PnpExtractionResultNeo4jRepository } from './pnp-extraction-result.neo4j.repository';
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 {}
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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<void> {
Expand Down Expand Up @@ -55,5 +57,7 @@ export class ExtractProductsFromPnpHandler
actionableProductRows,
session: event.session,
});

await this.planningExtractionResultSaver.save(file.latestVersionId, result);
}
}
2 changes: 2 additions & 0 deletions src/components/product/product.module.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -20,6 +21,7 @@ import { ProductService } from './product.service';
ScriptureModule,
FileModule,
StoryModule,
PnpExtractionResultModule,
],
providers: [
ProductResolver,
Expand Down

0 comments on commit 3b97014

Please sign in to comment.