From 395d6ecf3e6784570b6d265085ce85a1c0b55bd4 Mon Sep 17 00:00:00 2001 From: Sean Sundberg Date: Wed, 20 Sep 2023 07:52:15 -0500 Subject: [PATCH] Add service and endpoint to re-issue AI calls on case (#33) Signed-off-by: Sean Sundberg --- schema.gql | 1 + src/resolvers/kyc-case/kyc-case.resolver.ts | 7 ++++ .../kyc-case/kyc-case-management.api.ts | 1 + .../kyc-case/kyc-case-management.mock.ts | 42 +++++++++++++++---- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/schema.gql b/schema.gql index a4c8021..1a5c2b9 100644 --- a/schema.gql +++ b/schema.gql @@ -101,6 +101,7 @@ type Mutation { addDocumentToCase(caseId: ID!, documentName: String!, documentUrl: String!): KycCase! approveCase(case: ApproveCaseInput!): KycCase! createCase(customer: CustomerInput!): KycCase! + processCase(id: ID!): KycCase! removeDocumentFromCase(caseId: ID!, documentId: ID!): KycCase! reviewCase(case: ReviewCaseInput!): KycCase! } diff --git a/src/resolvers/kyc-case/kyc-case.resolver.ts b/src/resolvers/kyc-case/kyc-case.resolver.ts index 217c23e..4276916 100644 --- a/src/resolvers/kyc-case/kyc-case.resolver.ts +++ b/src/resolvers/kyc-case/kyc-case.resolver.ts @@ -90,4 +90,11 @@ export class KycCaseResolver { ): Promise { return this.service.approveCase(approveCase); } + + @Mutation(() => KycCase) + async processCase( + @Args('id', { type: () => ID }) caseId: string, + ): Promise { + return this.service.processCase(caseId); + } } diff --git a/src/services/kyc-case/kyc-case-management.api.ts b/src/services/kyc-case/kyc-case-management.api.ts index e5dcd35..72e74c9 100644 --- a/src/services/kyc-case/kyc-case-management.api.ts +++ b/src/services/kyc-case/kyc-case-management.api.ts @@ -22,6 +22,7 @@ export abstract class KycCaseManagementApi { abstract removeDocumentFromCase(id: string, documentId: string): Promise; abstract reviewCase(input: ReviewCaseModel): Promise; abstract approveCase(input: ApproveCaseModel): Promise; + abstract processCase(id: string): Promise; } export class CaseNotFound extends Error { diff --git a/src/services/kyc-case/kyc-case-management.mock.ts b/src/services/kyc-case/kyc-case-management.mock.ts index 54b76f8..2f387a6 100644 --- a/src/services/kyc-case/kyc-case-management.mock.ts +++ b/src/services/kyc-case/kyc-case-management.mock.ts @@ -26,7 +26,7 @@ import { Cp4adminCustomerRiskAssessmentCustomerRiskAssessmentApiFactory, customerRiskAssessmentConfig } from "../customer-risk-assessment"; -import {NegativeNewsApi} from "../negative-news"; +import {NegativeNewsApi, NewsScreeningResultModel} from "../negative-news"; import {DefaultApiFactory, kycCaseSummaryConfig} from "../kyc-case-summary"; import {NegativeNewsImpl} from "../negative-news/negative-news.impl"; @@ -167,7 +167,7 @@ export class KycCaseManagementMock implements KycCaseManagementApi { this.subject.next(this.subject.value); if (status === 'Pending') { - this.processCase(currentCase) + this.processCaseInternal(currentCase) .catch(err => console.error('Error processing case', {err})) } @@ -186,13 +186,23 @@ export class KycCaseManagementMock implements KycCaseManagementApi { this.subject.next(this.subject.value); - this.processCase(currentCase) + this.processCaseInternal(currentCase) .catch(err => console.error('Error processing case', {err})) return currentCase; } - async processCase(currentCase: KycCaseModel) { + async processCase(id: string): Promise { + const currentCase = await this.getCase(id); + + + this.processCaseInternal(currentCase) + .catch(err => console.error('Error processing case', {err})) + + return currentCase; + } + + async processCaseInternal(currentCase: KycCaseModel) { const getSubjectCase = (currentCase: {id: string}): KycCaseModel => { return first(this.subject.value @@ -221,7 +231,7 @@ export class KycCaseManagementMock implements KycCaseManagementApi { this.subject.next(this.subject.value); }); - this.negativeNews(currentCase.customer) + this.negativeNews(currentCase.customer, currentCase.negativeScreening) .then(news => { const subjectCase = getSubjectCase(currentCase); @@ -242,7 +252,7 @@ export class KycCaseManagementMock implements KycCaseManagementApi { this.subject.next(this.subject.value); }) - this.negativeNews(currentCase.counterparty) + this.negativeNews(currentCase.counterparty, currentCase.counterpartyNegativeScreening) .then(news => { const subjectCase = getSubjectCase(currentCase); @@ -284,7 +294,11 @@ export class KycCaseManagementMock implements KycCaseManagementApi { }) } - async negativeNews(person: PersonModel): Promise { + async negativeNews(person: PersonModel, currentNews?: NegativeScreeningModel): Promise { + if (currentNews && !currentNews.error) { + return currentNews; + } + return this.negNewsService.screenPerson(person) .then(result => ({result: result.summary})) } @@ -292,6 +306,10 @@ export class KycCaseManagementMock implements KycCaseManagementApi { async customerRiskAssessment(kycCase: KycCaseModel): Promise { const config = customerRiskAssessmentConfig(); + if (kycCase.customerRiskAssessment && !kycCase.customerRiskAssessment.error) { + return kycCase.customerRiskAssessment; + } + const api = Cp4adminCustomerRiskAssessmentCustomerRiskAssessmentApiFactory(config); const body = { @@ -307,21 +325,29 @@ export class KycCaseManagementMock implements KycCaseManagementApi { .then(riskAssessment => ({ score: riskAssessment.customerRiskAssessmentScore || 0, rating: riskAssessment.customerRiskAssessmentRating || 'N/A', - })); + })) } async summarizeCase(kycCase: KycCaseModel): Promise { const config = kycCaseSummaryConfig(); const options = {baseURL: process.env.KYC_SUMMARY_BASE_PATH}; + + if (kycCase.caseSummary && !kycCase.caseSummary.error) { + return kycCase.caseSummary + } const api = DefaultApiFactory(config); const financialDoc: DocumentModel | undefined = this.findFinancialDoc(kycCase.documents) if (financialDoc) { + console.log('Uploading financial document: ' + financialDoc.name) + const fileContents: Blob = new Blob([financialDoc.content], {type: getType(financialDoc.name)}); await api.uploadFinancialsPostForm(fileContents, options); } + console.log('Getting summary: ' + kycCase.customer.name) + const result = await api.requestSummaryPost({entity: kycCase.customer.name}, options); console.log('Summarize result: ', {summary: result.data});