Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion services/workflows-service/prisma/data-migrations
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { CollectionFlowStateService } from './services/collection-flow-state.ser
import { CollectionFlowDocumentsController } from './controllers/collection-flow.documents.controller';
import { CollectionFlowDocumentsService } from './services/collection-flow-documents.service';
import { DocumentFileModule } from '@/document-file/document-file.module';
import { CollectionFlowUtilityModule } from './services/сollection-flow-utility/collection-flow-utility.module';

@Module({
imports: [
Expand All @@ -67,6 +68,7 @@ import { DocumentFileModule } from '@/document-file/document-file.module';
forwardRef(() => WorkflowModule),
DocumentModule,
DocumentFileModule,
CollectionFlowUtilityModule,
],
controllers: [
CollectionFlowController,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
DocumentStatus,
EndUserVariant,
UiDefinition,
WorkflowRuntimeData,
} from '@prisma/client';
import { findEntityFieldsDefinition } from '../helpers/find-entity-fields-definition';
import { findDocumentDefinitionByTypeAndCategory } from '../helpers/find-document-definition-by-type-and-category';
Expand All @@ -38,6 +37,7 @@ import {
} from '@/prisma/prisma.util';
import { PrismaService } from '@/prisma/prisma.service';
import { assertIsValidProjectIds } from '@/project/project-scope.service';
import { CollectionFlowUtilityService } from './сollection-flow-utility/collection-flow-utility.service';

@Injectable()
export class CollectionFlowStateService {
Expand All @@ -49,6 +49,7 @@ export class CollectionFlowStateService {
protected readonly workflowService: WorkflowService,
protected readonly appLogger: AppLoggerService,
protected readonly prismaService: PrismaService,
protected readonly collectionFlowUtilityService: CollectionFlowUtilityService,
) {}

async getCollectionFlowState(workflowId: string, projectIds: TProjectIds) {
Expand All @@ -60,6 +61,15 @@ export class CollectionFlowStateService {
);

const collectionFlowState = getCollectionFlowState(workflowWithRelations.context);
const isCollectionFlowStateSupported =
await this.collectionFlowUtilityService.isCollectionFlowStateSupported(
workflowId,
projectIds,
);

if (!isCollectionFlowStateSupported) {
return null;
}

if (!collectionFlowState) {
throw new CollectionFlowMissingException();
Expand Down Expand Up @@ -281,41 +291,6 @@ export class CollectionFlowStateService {
return collectionFlowState.status;
}

private getEntityIdsFromWorkflow(
workflow: WorkflowRuntimeData & {
childWorkflowsRuntimeData: WorkflowRuntimeData[];
},
): Array<{ entityId: string; entityType: TEntityType }> {
const entityIds: Array<{ entityId: string; entityType: TEntityType }> = [
{
entityId: workflow.context.entity.ballerineEntityId,
entityType: EntityType.business,
},
];

workflow.childWorkflowsRuntimeData?.forEach(childWorkflow => {
if (!childWorkflow.endUserId) {
throw new Error('End user ID not found on child workflow.');
}

entityIds.push({
entityId: childWorkflow.endUserId,
entityType: EntityType.ubo,
});
});

workflow.context?.entity?.data?.additionalInfo?.directors?.forEach(
(director: { ballerineEntityId: string }) => {
entityIds.push({
entityId: director.ballerineEntityId,
entityType: EntityType.director,
});
},
);

return entityIds;
}

async updateCollectionFlowState(
workflowId: string,
newState: UpdateCollectionFlowStateDto,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// eslint-disable-next-line import/no-cycle
import { WorkflowModule } from '@/workflow/workflow.module';
import { forwardRef, Module } from '@nestjs/common';
import { CollectionFlowUtilityService } from './collection-flow-utility.service';
import { UiDefinitionModule } from '@/ui-definition/ui-definition.module';

@Module({
imports: [
// eslint-disable-next-line import/no-cycle
forwardRef(() => WorkflowModule),
UiDefinitionModule,
],
providers: [CollectionFlowUtilityService],
exports: [CollectionFlowUtilityService],
})
export class CollectionFlowUtilityModule {}
Comment on lines +1 to +16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Critical: Fix directory name with Cyrillic character.

The directory name contains a Cyrillic 'с' instead of Latin 'c' in "сollection-flow-utility". This can cause serious issues with:

  • File system operations on different OS
  • Git operations and version control
  • Developer tools and IDEs
  • Build processes

Rename the directory from сollection-flow-utility to collection-flow-utility (using Latin 'c').

The module structure itself is correct with proper handling of circular dependencies using forwardRef.

🤖 Prompt for AI Agents
In
services/workflows-service/src/collection-flow/services/сollection-flow-utility/collection-flow-utility.module.ts
lines 1 to 16, the directory name "сollection-flow-utility" uses a Cyrillic 'с'
instead of a Latin 'c', which can cause cross-platform and tooling issues.
Rename the directory to use the Latin 'c' as "collection-flow-utility" and
update all related import paths accordingly to ensure consistency and avoid
errors.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { isPrismaException } from '@/common/is-prisma-exception/is-prisma-exception';
import { TProjectIds } from '@/types';
import { UiDefinitionService } from '@/ui-definition/ui-definition.service';
import { WorkflowService } from '@/workflow/workflow.service';
import { forwardRef, Inject, Injectable } from '@nestjs/common';

@Injectable()
export class CollectionFlowUtilityService {
constructor(
@Inject(forwardRef(() => WorkflowService))
protected readonly workflowService: WorkflowService,
protected readonly uiDefinitionService: UiDefinitionService,
) {}

async isCollectionFlowStateSupported(workflowId: string, projectIds: TProjectIds) {
const workflowDefinition = await this.workflowService.getWorkflowByIdWithRelations(
workflowId,
projectIds,
);

try {
await this.uiDefinitionService.getByWorkflowDefinitionId(
workflowDefinition.workflowDefinitionId,
'collection_flow',
projectIds,
);

return true;
} catch (error) {
if (isPrismaException(error) && error.code === 'P2025') {
return false;
}

throw error;
}
}
}
Comment on lines +1 to +37
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Critical: Fix directory name with Cyrillic character.

Same issue as the module file - the directory name contains a Cyrillic 'с' instead of Latin 'c' in "сollection-flow-utility".

Rename the directory from сollection-flow-utility to collection-flow-utility (using Latin 'c').

🤖 Prompt for AI Agents
In
services/workflows-service/src/collection-flow/services/сollection-flow-utility/collection-flow-utility.service.ts
lines 1 to 37, the directory name "сollection-flow-utility" contains a Cyrillic
'с' instead of a Latin 'c'. Rename the directory to "collection-flow-utility"
using the Latin 'c' to fix the character encoding issue and ensure proper module
resolution.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { isType } from '@ballerine/common';
import { PrismaClientKnownRequestError } from '@prisma/client/runtime';
import { z } from 'zod';

export const isPrismaException = (value: unknown): value is PrismaClientKnownRequestError =>
isType(z.object({ code: z.string() }))(value);
2 changes: 2 additions & 0 deletions services/workflows-service/src/document/document.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { WorkflowModule } from '@/workflow/workflow.module';
import { UiDefinitionModule } from '@/ui-definition/ui-definition.module';
import { WorkflowDefinitionModule } from '@/workflow-defintion/workflow-definition.module';
import { ProjectScopeService } from '@/project/project-scope.service';
import { CollectionFlowUtilityModule } from '@/collection-flow/services/сollection-flow-utility/collection-flow-utility.module';

@Module({
imports: [
Expand All @@ -19,6 +20,7 @@ import { ProjectScopeService } from '@/project/project-scope.service';
forwardRef(() => WorkflowModule),
UiDefinitionModule,
WorkflowDefinitionModule,
CollectionFlowUtilityModule,
],
controllers: [DocumentControllerExternal],
providers: [DocumentService, DocumentRepository, ProjectScopeService],
Expand Down
33 changes: 24 additions & 9 deletions services/workflows-service/src/document/document.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ import {
EntitySchema,
TParsedDocuments,
} from './types';
import { defaultPrismaTransactionOptions } from '@/prisma/prisma.util';
import { beginTransactionIfNotExistCurry } from '@/prisma/prisma.util';
import {
defaultPrismaTransactionOptions,
beginTransactionIfNotExistCurry,
} from '@/prisma/prisma.util';
import { PrismaService } from '@/prisma/prisma.service';
import { assertIsValidProjectIds } from '@/project/project-scope.service';
import { CollectionFlowUtilityService } from '@/collection-flow/services/сollection-flow-utility/collection-flow-utility.service';

@Injectable()
export class DocumentService {
Expand All @@ -58,6 +61,7 @@ export class DocumentService {
protected readonly uiDefinitionService: UiDefinitionService,
protected readonly workflowDefinitionService: WorkflowDefinitionService,
protected readonly prismaService: PrismaService,
protected readonly collectionFlowUtilityService: CollectionFlowUtilityService,
) {}

async create(
Expand Down Expand Up @@ -806,6 +810,23 @@ export class DocumentService {
}

async getDocumentTrackerByWorkflowId(projectId: TProjectId, workflowId: string) {
const defaultTrackerItems = {
business: [],
individuals: {
ubos: [],
directors: [],
},
};

const isCollectionFlowStateSupported =
await this.collectionFlowUtilityService.isCollectionFlowStateSupported(workflowId, [
projectId,
]);

if (!isCollectionFlowStateSupported) {
return defaultTrackerItems;
}

const uiDefinition = await this.uiDefinitionService.getByRuntimeId(
workflowId,
'collection_flow',
Expand All @@ -817,13 +838,7 @@ export class DocumentService {
.safeParse(uiDefinition.uiSchema);

if (!uiSchemaValidation.success) {
return {
business: [],
individuals: {
ubos: [],
directors: [],
},
};
return defaultTrackerItems;
}

const workflowDataWithEndUsers = await this.workflowService.getWorkflowByIdWithRelations(
Expand Down
Loading