Skip to content

Commit

Permalink
Update kyc summary logic (#30)
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 74ab30f commit c41bdd1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 30 deletions.
7 changes: 6 additions & 1 deletion .env.template
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
IAM_URL=""

WML_URL=""
WML_PROJECT_ID=""
MODEL_ID=""
PROJECT_ID=""
DISCOVERY_PROJECT_ID=""
DECODING_METHOD=""
MAX_NEW_TOKENS=""
REPETITION_PENALTY=""

DISCOVERY_URL=""
DISCOVERY_VERSION=""

KYC_SUMMARY_BASE_PATH=""
CRA_BASE_PATH=""

CRA_USERNAME=""
CRA_PASSWORD=""
CRA_API_KEY=""

WML_API_KEY=""

Expand Down
6 changes: 3 additions & 3 deletions src/models/kyc-case.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ export const createEmptyCase = (): KycCaseModel => {
id: 'new',
customer: {
name: '',
countryOfResidence: 'US',
countryOfResidence: 'United States',
personalIdentificationNumber: '',
industryType: '',
entityType: '',
industryType: 'Private Limited Company',
entityType: 'Growing of rice',
},
status: 'New',
documents: [],
Expand Down
36 changes: 24 additions & 12 deletions src/services/kyc-case/kyc-case-management.mock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {BehaviorSubject, Observable} from "rxjs";
import mime from 'mime';
import streamToBlob from 'stream-to-blob';
import {getType} from 'mime';
import * as streamToBlob from 'stream-to-blob';
import * as Stream from "stream";

import {CaseNotFound, KycCaseManagementApi} from "./kyc-case-management.api";
Expand Down Expand Up @@ -47,7 +47,7 @@ const initialValue: KycCaseModel[] = [
id: '2',
customer: {
name: 'Jane Doe',
countryOfResidence: 'CA',
countryOfResidence: 'Canada',
personalIdentificationNumber: 'AB1458690',
entityType: 'Sole Trader',
industryType: 'Extraction of crude petroleum',
Expand Down Expand Up @@ -294,12 +294,15 @@ export class KycCaseManagementMock implements KycCaseManagementApi {

const api = Cp4adminCustomerRiskAssessmentCustomerRiskAssessmentApiFactory(config);

const body = {
nonPersonalEntityType: kycCase.customer.entityType,
nonPersonalGeographyType: kycCase.customer.countryOfResidence,
nonPersonalIndustryType: kycCase.customer.industryType,
};

console.log('Getting customer risk assessment: ', body)
return api
.customerRiskAssessmentRiskAssessment({
nonPersonalEntityType: kycCase.customer.entityType,
nonPersonalGeographyType: kycCase.customer.countryOfResidence,
nonPersonalIndustryType: kycCase.customer.industryType,
})
.customerRiskAssessmentRiskAssessment(body)
.then(result => result.data)
.then(riskAssessment => ({
score: riskAssessment.customerRiskAssessmentScore || 0,
Expand All @@ -309,16 +312,17 @@ export class KycCaseManagementMock implements KycCaseManagementApi {

async summarizeCase(kycCase: KycCaseModel): Promise<KycCaseSummaryModel> {
const config = kycCaseSummaryConfig();
const options = {baseURL: process.env.KYC_SUMMARY_BASE_PATH};
const api = DefaultApiFactory(config);

const financialDoc: DocumentModel | undefined = this.findFinancialDoc(kycCase.documents)

if (financialDoc) {
const fileContents: Blob = await streamToBlob(financialDoc.content, mime.getType(financialDoc.path));
await api.uploadFinancialsPostForm(fileContents);
const fileContents: Blob = new Blob([financialDoc.content], {type: getType(financialDoc.name)});
await api.uploadFinancialsPostForm(fileContents, options);
}

const result = await api.requestSummaryPost({entity: kycCase.customer.name})
const result = await api.requestSummaryPost({entity: kycCase.customer.name}, options);

console.log('Summarize result: ', {summary: result.data});

Expand All @@ -327,7 +331,15 @@ export class KycCaseManagementMock implements KycCaseManagementApi {

findFinancialDoc(documents: DocumentModel[]): DocumentModel | undefined {
const financialDocRegEx = /.*financial.*/ig
const annualDocRegEx = /.*annual.*/ig

const doc = first(documents
.filter(doc => financialDocRegEx.test(doc.name) || annualDocRegEx.test(doc.name)))

if (doc) {
return doc;
}

return first(documents.filter(doc => financialDocRegEx.test(doc.name)))
return documents.length > 0 ? documents[0] : undefined;
}
}
24 changes: 10 additions & 14 deletions src/services/menu-options/menu-options.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import {MenuOptionsApi} from "./menu-options.api";
import {FormOptionModel} from "../../models";
import {parseCsv} from "../../utils";

const countryTypesCsv = `Code,description,risk_weight,
XG,EU Organisations,LOW,
NULL,Missing Data,MEDIUM,
NOT_FOUND,Data Not Recognised,MEDIUM,
XH,Other International Org.,LOW,
const countryTypesCsv = `XH,Other International Org.,LOW,
QU,Unknown,MEDIUM,
XB,Abu Dhabi,HIGH,
AF,Afghanistan,REFER-SANCTIONS,
Expand Down Expand Up @@ -268,8 +264,7 @@ ZR,Zaire (Democratic Republic Of Congo),REFER-SANCTIONS,
ZM,Zambia,HIGH,
ZW,Zimbabwe,REFER-SANCTIONS,`

const industryTypesCsv = `Code,Division,Industry ,Strategic Rating,
01.11,Growing of non-perennial crops,"Growing of cereals (except rice), leguminous crops and oil seeds",MEDIUM,
const industryTypesCsv = `01.11,Growing of non-perennial crops,"Growing of cereals (except rice), leguminous crops and oil seeds",MEDIUM,
01.12,Growing of non-perennial crops,Growing of rice,LOW,
01.13,Growing of non-perennial crops,"Growing of vegetables and melons, roots and tubers",MEDIUM,
01.14,Growing of non-perennial crops,Growing of sugar cane,LOW,
Expand Down Expand Up @@ -1008,9 +1003,7 @@ const industryTypesCsv = `Code,Division,Industry ,Strategic Rating,
NOT_FOUND,,Data Not Recognised,HIGH,
NULL,,MISSING DATA,HIGH,
`;
const entityTypesCsv = `
code,description,risk_weight
01,Private Limited Company,MEDIUM
const entityTypesCsv = `01,Private Limited Company,MEDIUM
02,Sole Trader,MEDIUM
03,Limited Liability Partnership,MEDIUM
04,Clubs,HIGH
Expand All @@ -1035,14 +1028,15 @@ export class MenuOptionsMock implements MenuOptionsApi {
return countryTypes;
}

return entityTypes = countryTypesCsv
return countryTypes = countryTypesCsv
.split('\n')
.map(parseCsv)
.filter((_, index) => index !== 0)
.map(values => ({
value: '' + values[1],
text: '' + values[1],
}))
.filter(val => val.value !== 'code');
.filter(val => val.text !== 'description')
}

async getEntityTypes(): Promise<FormOptionModel[]> {
Expand All @@ -1053,11 +1047,12 @@ export class MenuOptionsMock implements MenuOptionsApi {
return entityTypes = entityTypesCsv
.split('\n')
.map(parseCsv)
.filter((_, index) => index !== 0)
.map(values => ({
value: '' + values[1],
text: '' + values[1],
}))
.filter(val => val.value !== 'code');
.filter(val => val.value !== 'Code');
}

async getIndustries(): Promise<FormOptionModel[]> {
Expand All @@ -1068,10 +1063,11 @@ export class MenuOptionsMock implements MenuOptionsApi {
return industryTypes = industryTypesCsv
.split('\n')
.map(parseCsv)
.filter((_, index) => index !== 0)
.map(values => ({
value: '' + values[2],
text: '' + values[2],
}))
.filter(val => val.value !== 'Code');
.filter(val => val.text !== 'Division');
}
}

0 comments on commit c41bdd1

Please sign in to comment.