Skip to content

Commit

Permalink
Fixes for individual AML (#2324)
Browse files Browse the repository at this point in the history
* feat: fixes for individual AML

* feat: pr comment fix

* feat: pR comment fix
  • Loading branch information
tomer-shvadron committed Apr 25, 2024
1 parent a11b5af commit 397ee92
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 181 deletions.
13 changes: 7 additions & 6 deletions apps/backoffice-v2/src/domains/business-reports/fetchers.ts
Expand Up @@ -3,12 +3,13 @@ import { apiClient } from '@/common/api-client/api-client';
import { Method } from '@/common/enums';
import { handleZodError } from '@/common/utils/handle-zod-error/handle-zod-error';

export const BusinessReportSchema = z.object({
report: z.object({
reportFileId: z.string(),
}),
});
export const BusinessReportsSchema = z.array(BusinessReportSchema);
export const BusinessReportSchema = z
.object({
report: z.object({
reportFileId: z.string(),
}),
})
.optional();

export const fetchBusinessReports = async ({
businessId,
Expand Down
Expand Up @@ -6,74 +6,75 @@ const SourceInfoSchema = z.object({
date: z.string().optional().nullable(),
});

const ListingRelatedToMatchSchema = z.object({
warnings: z.array(SourceInfoSchema).optional().nullable(),
sanctions: z.array(SourceInfoSchema).optional().nullable(),
pep: z.array(SourceInfoSchema).optional().nullable(),
adverseMedia: z.array(SourceInfoSchema).optional().nullable(),
});

const HitSchema = z.object({
matchedName: z.string().optional().nullable(),
dateOfBirth: z.string().optional().nullable(),
countries: z.array(z.string()).optional().nullable(),
matchTypes: z.array(z.string()).optional().nullable(),
aka: z.array(z.string()).optional().nullable(),
listingsRelatedToMatch: ListingRelatedToMatchSchema.optional().nullable(),
warnings: z.array(SourceInfoSchema).optional().nullable(),
sanctions: z.array(SourceInfoSchema).optional().nullable(),
pep: z.array(SourceInfoSchema).optional().nullable(),
adverseMedia: z.array(SourceInfoSchema).optional().nullable(),
});

export const AmlSchema = z.object({
hits: z.array(HitSchema).optional().nullable(),
createdAt: z.string().optional().nullable(),
totalHits: z.number().optional().nullable(),
});

export type TAml = z.output<typeof AmlSchema>;

export const amlAdapter = (aml: TAml) => {
const { hits, totalHits, createdAt, ...rest } = aml;
const { hits, createdAt, ...rest } = aml;

return {
totalMatches: totalHits ?? 0,
totalMatches: hits?.length ?? 0,
fullReport: rest,
dateOfCheck: createdAt,
matches:
hits?.map(
({ matchedName, dateOfBirth, countries, matchTypes, aka, listingsRelatedToMatch }) => {
const { sanctions, warnings, pep, adverseMedia } = listingsRelatedToMatch ?? {};

return {
matchedName,
dateOfBirth,
countries: countries?.join(', ') ?? '',
matchTypes: matchTypes?.join(', ') ?? '',
aka: aka?.join(', ') ?? '',
sanctions:
sanctions?.map(sanction => ({
sanction: sanction?.sourceName,
date: sanction?.date,
source: sanction?.sourceUrl,
})) ?? [],
warnings:
warnings?.map(warning => ({
warning: warning?.sourceName,
date: warning?.date,
source: warning?.sourceUrl,
})) ?? [],
pep:
pep?.map(pepItem => ({
person: pepItem?.sourceName,
date: pepItem?.date,
source: pepItem?.sourceUrl,
})) ?? [],
adverseMedia:
adverseMedia?.map(adverseMediaItem => ({
entry: adverseMediaItem?.sourceName,
date: adverseMediaItem?.date,
source: adverseMediaItem?.sourceUrl,
})) ?? [],
};
},
({
matchedName,
dateOfBirth,
countries,
matchTypes,
aka,
sanctions,
warnings,
pep,
adverseMedia,
}) => ({
matchedName,
dateOfBirth,
countries: countries?.join(', ') ?? '',
matchTypes: matchTypes?.join(', ') ?? '',
aka: aka?.join(', ') ?? '',
sanctions:
sanctions?.map(sanction => ({
sanction: sanction?.sourceName,
date: sanction?.date,
source: sanction?.sourceUrl,
})) ?? [],
warnings:
warnings?.map(warning => ({
warning: warning?.sourceName,
date: warning?.date,
source: warning?.sourceUrl,
})) ?? [],
pep:
pep?.map(pepItem => ({
person: pepItem?.sourceName,
date: pepItem?.date,
source: pepItem?.sourceUrl,
})) ?? [],
adverseMedia:
adverseMedia?.map(adverseMediaItem => ({
entry: adverseMediaItem?.sourceName,
date: adverseMediaItem?.date,
source: adverseMediaItem?.sourceUrl,
})) ?? [],
}),
) ?? [],
};
};
Expand Up @@ -650,7 +650,6 @@ export const workflow = {
result: {
vendorResult: {
aml: {
totalHits: 1,
createdAt: faker.date.recent().toISOString(),
hits: [
{
Expand All @@ -659,105 +658,99 @@ export const workflow = {
countries: ['US', 'GB'],
matchTypes: ['year_of_birth', 'full_name', 'last_name'],
matchedName: `John Doe`,
listingsRelatedToMatch: {
warnings: [
{
sourceUrl:
'http://www.treasury.gov/resource-center/sanctions/SDN-List/Pages/default.aspx',
sourceName: 'FBI Most Wanted',
date: faker.date.recent().toISOString(),
},
{
sourceUrl:
'http://www.treasury.gov/resource-center/sanctions/SDN-List/Pages/default.aspx',
sourceName: 'FBI Most Wanted',
date: faker.date.recent().toISOString(),
},
],
sanctions: [
{
sourceUrl:
'http://www.treasury.gov/resource-center/sanctions/SDN-List/Pages/default.aspx',
sourceName: 'OFAC SDN List',
date: faker.date.recent().toISOString(),
},
{
sourceUrl:
'http://www.treasury.gov/resource-center/sanctions/SDN-List/Pages/default.aspx',
sourceName: 'OFAC SDN List',
date: faker.date.recent().toISOString(),
},
],
pep: [
{
sourceName:
'United Kingdom Insolvency Service Disqualified Directors',
sourceUrl: 'https://www.navy.mil/Leadership/Biographies',
date: '2020-01-01',
},
],
adverseMedia: [
{
sourceName: "SNA's Old Salt Award Passed to Adm. Davidson",
sourceUrl:
'https://www.marinelink.com/amp/news/snas-old-salt-award-passed-adm-davidson-443093',
date: '2021-03-09',
},
],
},
warnings: [
{
sourceUrl:
'http://www.treasury.gov/resource-center/sanctions/SDN-List/Pages/default.aspx',
sourceName: 'FBI Most Wanted',
date: faker.date.recent().toISOString(),
},
{
sourceUrl:
'http://www.treasury.gov/resource-center/sanctions/SDN-List/Pages/default.aspx',
sourceName: 'FBI Most Wanted',
date: faker.date.recent().toISOString(),
},
],
sanctions: [
{
sourceUrl:
'http://www.treasury.gov/resource-center/sanctions/SDN-List/Pages/default.aspx',
sourceName: 'OFAC SDN List',
date: faker.date.recent().toISOString(),
},
{
sourceUrl:
'http://www.treasury.gov/resource-center/sanctions/SDN-List/Pages/default.aspx',
sourceName: 'OFAC SDN List',
date: faker.date.recent().toISOString(),
},
],
pep: [
{
sourceName: 'United Kingdom Insolvency Service Disqualified Directors',
sourceUrl: 'https://www.navy.mil/Leadership/Biographies',
date: '2020-01-01',
},
],
adverseMedia: [
{
sourceName: "SNA's Old Salt Award Passed to Adm. Davidson",
sourceUrl:
'https://www.marinelink.com/amp/news/snas-old-salt-award-passed-adm-davidson-443093',
date: '2021-03-09',
},
],
},
{
aka: ['John Doe', 'John Smith'],
dateOfBirth: '1992-04-13',
countries: ['US', 'GB'],
matchTypes: ['year_of_birth', 'full_name', 'last_name'],
matchedName: `John Doe`,
listingsRelatedToMatch: {
warnings: [
{
sourceUrl:
'http://www.treasury.gov/resource-center/sanctions/SDN-List/Pages/default.aspx',
sourceName: 'FBI Most Wanted',
date: faker.date.recent().toISOString(),
},
{
sourceUrl:
'http://www.treasury.gov/resource-center/sanctions/SDN-List/Pages/default.aspx',
sourceName: 'FBI Most Wanted',
date: faker.date.recent().toISOString(),
},
],
sanctions: [
{
sourceUrl:
'http://www.treasury.gov/resource-center/sanctions/SDN-List/Pages/default.aspx',
sourceName: 'OFAC SDN List',
date: faker.date.recent().toISOString(),
},
{
sourceUrl:
'http://www.treasury.gov/resource-center/sanctions/SDN-List/Pages/default.aspx',
sourceName: 'OFAC SDN List',
date: faker.date.recent().toISOString(),
},
],
pep: [
{
sourceName:
'United Kingdom Insolvency Service Disqualified Directors',
sourceUrl: 'https://www.navy.mil/Leadership/Biographies',
date: '2020-01-01',
},
],
adverseMedia: [
{
sourceName: "SNA's Old Salt Award Passed to Adm. Davidson",
sourceUrl:
'https://www.marinelink.com/amp/news/snas-old-salt-award-passed-adm-davidson-443093',
date: '2021-03-09',
},
],
},
warnings: [
{
sourceUrl:
'http://www.treasury.gov/resource-center/sanctions/SDN-List/Pages/default.aspx',
sourceName: 'FBI Most Wanted',
date: faker.date.recent().toISOString(),
},
{
sourceUrl:
'http://www.treasury.gov/resource-center/sanctions/SDN-List/Pages/default.aspx',
sourceName: 'FBI Most Wanted',
date: faker.date.recent().toISOString(),
},
],
sanctions: [
{
sourceUrl:
'http://www.treasury.gov/resource-center/sanctions/SDN-List/Pages/default.aspx',
sourceName: 'OFAC SDN List',
date: faker.date.recent().toISOString(),
},
{
sourceUrl:
'http://www.treasury.gov/resource-center/sanctions/SDN-List/Pages/default.aspx',
sourceName: 'OFAC SDN List',
date: faker.date.recent().toISOString(),
},
],
pep: [
{
sourceName: 'United Kingdom Insolvency Service Disqualified Directors',
sourceUrl: 'https://www.navy.mil/Leadership/Biographies',
date: '2020-01-01',
},
],
adverseMedia: [
{
sourceName: "SNA's Old Salt Award Passed to Adm. Davidson",
sourceUrl:
'https://www.marinelink.com/amp/news/snas-old-salt-award-passed-adm-davidson-443093',
date: '2021-03-09',
},
],
},
],
},
Expand Down
2 changes: 1 addition & 1 deletion services/workflows-service/prisma/data-migrations
25 changes: 11 additions & 14 deletions services/workflows-service/scripts/workflows/workflow-runtime.ts
Expand Up @@ -403,7 +403,6 @@ const createAmlData = ({ ubo }: { ubo: Workflow['ubos'][number] }) => {
name: `${ubo.firstName} ${ubo.lastName}`,
year: ubo.dateOfBirth.getFullYear(),
},
totalHits: 1,
createdAt: faker.date.recent().toISOString(),
hits: [
{
Expand All @@ -413,19 +412,17 @@ const createAmlData = ({ ubo }: { ubo: Workflow['ubos'][number] }) => {
dateOfBirth: ubo.dateOfBirth.toISOString().split('T')[0],
dateOfDeath: null,
matchedName: `${ubo.firstName} ${ubo.lastName}`,
listingsRelatedToMatch: {
pep: [],
warnings: [],
sanctions: [
{
sourceUrl:
'http://www.treasury.gov/resource-center/sanctions/SDN-List/Pages/default.aspx',
sourceName: 'OFAC SDN List',
},
],
fitnessProbity: [],
adverseMedia: [],
},
pep: [],
warnings: [],
sanctions: [
{
sourceUrl:
'http://www.treasury.gov/resource-center/sanctions/SDN-List/Pages/default.aspx',
sourceName: 'OFAC SDN List',
},
],
fitnessProbity: [],
adverseMedia: [],
},
],
};
Expand Down

0 comments on commit 397ee92

Please sign in to comment.