Skip to content

Commit

Permalink
feat: updated schema of config and docs + common bump
Browse files Browse the repository at this point in the history
  • Loading branch information
Blokh committed Nov 30, 2023
1 parent 20b3f68 commit 59afd0b
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 38 deletions.
5 changes: 5 additions & 0 deletions .changeset/lovely-elephants-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ballerine/common': patch
---

updated types and functionalities
2 changes: 1 addition & 1 deletion apps/backoffice-v2/src/domains/workflows/fetchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const BaseWorkflowByIdSchema = z.object({
workflowDefinition: ObjectWithIdSchema.extend({
name: z.string(),
contextSchema: z.record(z.any(), z.any()).nullable(),
documentsSchema: z.record(z.string(), z.any()).optional(),
documentsSchema: z.array(z.any()).optional(),
config: z.record(z.any(), z.any()).nullable(),
}),
createdAt: z.string().datetime(),
Expand Down
39 changes: 21 additions & 18 deletions apps/backoffice-v2/src/pages/Entity/hooks/useTasks/useTasks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import {
getDocumentSchemaByDefinition,
isNullish,
StateTag,
TAvailableDocuments,
TDocument,
TDocumentsWithAvailability,
} from '@ballerine/common';
import * as React from 'react';
import { ComponentProps, useMemo } from 'react';
Expand Down Expand Up @@ -45,32 +45,35 @@ const pluginsOutputBlacklist = [
];

function getDocumentsSchemas(issuerCountryCode, workflow: TWorkflowById) {
return (
const data = getDocumentSchemaByDefinition(
issuerCountryCode,
workflow.workflowDefinition?.documentsSchema as TDocument[],
);
const filters =
issuerCountryCode &&
getDocumentSchemaByDefinition(
issuerCountryCode,
workflow.workflowDefinition?.documentsSchema as TDocumentsWithAvailability,
)
data
.concat(getDocumentsByCountry(issuerCountryCode))
.reduce((unique: TDocument[], item: TDocument) => {
const isDuplicate = unique.some(u => u.type === item.type && u.category === item.category);
if (!isDuplicate) {
unique.push(item);
}
return unique;
}, [] as TDocument[])
.filter((documentSchema: TDocument) => {
if (!workflow.workflowDefinition.documentsSchema?.availableDocuments) return true;
}, [] as TDocument[]);

const isInside = !!workflow.workflowDefinition.documentsSchema?.availableDocuments.find(
(availableDocument: TDocumentsWithAvailability['availableDocuments'][number]) =>
availableDocument.type === documentSchema.type &&
availableDocument.category === documentSchema.category,
);
const filteredDocs = filters.filter((documentSchema: TDocument) => {
if (!workflow.workflowDefinition.config?.availableDocuments) return true;

return isInside;
})
);
const isIncludes = !!workflow.workflowDefinition.config?.availableDocuments.find(
(availableDocument: TAvailableDocuments[number]) =>
availableDocument.type === documentSchema.type &&
availableDocument.category === documentSchema.category,
);

return isIncludes;
});
debugger;
return filteredDocs;
}

export const useTasks = ({
Expand Down Expand Up @@ -134,7 +137,7 @@ export const useTasks = ({
const issuerCountryCode = extractCountryCodeFromWorkflow(workflow);

const documentsSchemas = getDocumentsSchemas(issuerCountryCode, workflow);

debugger;
const registryInfoBlock =
Object.keys(filteredPluginsOutput ?? {}).length === 0
? []
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export type {
DefaultContextSchema,
TDefaultSchemaDocumentPage,
TDocument,
TDocumentsWithAvailability,
TAvailableDocuments,
} from './schemas';

export {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getGhanaDocuments } from './GH';
import { TDocument, TDocumentsWithAvailability } from '../types';
import { TDocument } from '../types';
import { countryCodes } from '@/countries';
import { DefaultContextSchema } from '@/schemas';
import { getCanadaDocuments } from './CA';
Expand All @@ -19,12 +19,10 @@ export const getDocumentsByCountry = (countryCode: (typeof countryCodes)[number]

export const getDocumentSchemaByDefinition = (
countryCode: (typeof countryCodes)[number],
documentsSchema: TDocumentsWithAvailability | undefined,
documentsSchema: TDocument[] | undefined,
): TDocument[] => {
return (
documentsSchema?.schema?.filter(
documentSchema => documentSchema.issuer.country === countryCode,
) || []
documentsSchema?.filter(documentSchema => documentSchema.issuer.country === countryCode) || []
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,4 @@ export type TDocument = Omit<DefaultContextSchema['documents'][number], 'pages'
propertiesSchema: JSONSchema7;
};

export type TDocumentsWithAvailability = {
availableDocuments: Array<{ category: string; type: string }>;
schema: TDocument[];
};
export type TAvailableDocuments = Array<{ category: string; type: string }>;
2 changes: 1 addition & 1 deletion packages/common/src/schemas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export { defaultContextSchema } from './documents/default-context-schema';
export { getGhanaDocuments } from './documents/workflow/documents/schemas/GH';
export { getDocumentsByCountry, getDocumentId } from './documents/workflow/documents/schemas/index';
export { type TDocument } from './documents/workflow/documents/types';
export { type TDocumentsWithAvailability } from './documents/workflow/documents/types';
export { type TAvailableDocuments } from './documents/workflow/documents/types';
export { getDocumentSchemaByDefinition } from './documents/workflow/documents/schemas/index';
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion services/workflows-service/prisma/data-migrations
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const ConfigSchema = z
isLockedDocumentCategoryAndType: z.boolean().optional(),
allowMultipleActiveWorkflows: z.boolean().optional(),
initialEvent: z.string().optional(),
availableDocuments: z.array(z.object({ category: z.string(), type: z.string() })).optional(),
callbackResult: z
.object({
transformers: z.array(z.any()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
getDocumentsByCountry,
isObject,
TDocument,
type TDocumentsWithAvailability,
} from '@ballerine/common';
import { WorkflowDefinition } from '@prisma/client';

Expand All @@ -17,7 +16,7 @@ export const addPropertiesSchemaToDocument = (
(documentSchema &&
getPropertiesFromDefinition(
document,
documentSchema as TDocumentsWithAvailability,
documentSchema as TDocument[],
document?.issuer?.country,
)) ||
getPropertiesSchemaForDocument(document);
Expand All @@ -37,10 +36,10 @@ function getPropertiesSchemaForDocument(document: DefaultContextSchema['document

const getPropertiesFromDefinition = (
document: DefaultContextSchema['documents'][number],
documentsSchema: TDocumentsWithAvailability,
documentsSchema: TDocument[],
countryCode: string,
): ReturnType<typeof getPropertiesSchemaForDocument> | undefined => {
const localizedDocumentSchemas = documentsSchema.schema.filter(
const localizedDocumentSchemas = documentsSchema.filter(
documentSchema => documentSchema.issuer.country === countryCode,
);

Expand Down

0 comments on commit 59afd0b

Please sign in to comment.