Skip to content

Commit

Permalink
Add service and endpoint to re-issue AI calls on case (#33)
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Sundberg <[email protected]>
  • Loading branch information
seansund authored Sep 20, 2023
1 parent a6d46d3 commit 395d6ec
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
1 change: 1 addition & 0 deletions schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -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!
}
Expand Down
7 changes: 7 additions & 0 deletions src/resolvers/kyc-case/kyc-case.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,11 @@ export class KycCaseResolver {
): Promise<KycCaseModel> {
return this.service.approveCase(approveCase);
}

@Mutation(() => KycCase)
async processCase(
@Args('id', { type: () => ID }) caseId: string,
): Promise<KycCaseModel> {
return this.service.processCase(caseId);
}
}
1 change: 1 addition & 0 deletions src/services/kyc-case/kyc-case-management.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export abstract class KycCaseManagementApi {
abstract removeDocumentFromCase(id: string, documentId: string): Promise<KycCaseModel>;
abstract reviewCase(input: ReviewCaseModel): Promise<KycCaseModel>;
abstract approveCase(input: ApproveCaseModel): Promise<KycCaseModel>;
abstract processCase(id: string): Promise<KycCaseModel>;
}

export class CaseNotFound extends Error {
Expand Down
42 changes: 34 additions & 8 deletions src/services/kyc-case/kyc-case-management.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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}))
}

Expand All @@ -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<KycCaseModel> {
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
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -284,14 +294,22 @@ export class KycCaseManagementMock implements KycCaseManagementApi {
})
}

async negativeNews(person: PersonModel): Promise<NegativeScreeningModel> {
async negativeNews(person: PersonModel, currentNews?: NegativeScreeningModel): Promise<NegativeScreeningModel> {
if (currentNews && !currentNews.error) {
return currentNews;
}

return this.negNewsService.screenPerson(person)
.then(result => ({result: result.summary}))
}

async customerRiskAssessment(kycCase: KycCaseModel): Promise<CustomerRiskAssessmentModel> {
const config = customerRiskAssessmentConfig();

if (kycCase.customerRiskAssessment && !kycCase.customerRiskAssessment.error) {
return kycCase.customerRiskAssessment;
}

const api = Cp4adminCustomerRiskAssessmentCustomerRiskAssessmentApiFactory(config);

const body = {
Expand All @@ -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<KycCaseSummaryModel> {
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});
Expand Down

0 comments on commit 395d6ec

Please sign in to comment.