Skip to content

Commit f35c58f

Browse files
authored
feat: reverted transaction in final submission (#3411)
1 parent 19d417b commit f35c58f

File tree

3 files changed

+35
-126
lines changed

3 files changed

+35
-126
lines changed

apps/kyb-app/src/common/utils/request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const instance = ky.create({
1313
methods: ['get'],
1414
},
1515
credentials: 'include',
16-
timeout: 30_000,
16+
timeout: 75_000,
1717
hooks: {
1818
beforeRequest: [
1919
request => {

services/workflows-service/src/collection-flow/controllers/collection-flow.controller.ts

Lines changed: 34 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ import * as common from '@nestjs/common';
2727
import { ApiExcludeController } from '@nestjs/swagger';
2828
import { CollectionFlowMissingException } from '../exceptions/collection-flow-missing.exception';
2929
import { CollectionFlowStateService } from '../services/collection-flow-state.service';
30-
import { defaultPrismaTransactionOptions } from '@/prisma/prisma.util';
31-
import { beginTransactionIfNotExistCurry } from '@/prisma/prisma.util';
3230
import { PrismaService } from '@/prisma/prisma.service';
3331

3432
@UseWorkflowAuthGuard()
@@ -159,94 +157,42 @@ export class CollectionFlowController {
159157
@common.Post('/final-submission')
160158
async finalSubmission(@TokenScope() tokenScope: ITokenScope, @common.Body() body: FinishFlowDto) {
161159
try {
162-
const beginTransaction = beginTransactionIfNotExistCurry({
163-
prismaService: this.prismaService,
164-
options: defaultPrismaTransactionOptions,
165-
});
166-
167-
return beginTransaction(async transaction => {
168-
const workflowRuntimeData = await this.workflowService.getWorkflowRuntimeDataById(
169-
tokenScope.workflowRuntimeDataId,
170-
{},
171-
[tokenScope.projectId],
172-
transaction,
173-
);
174-
175-
const directors = await this.collectionFlowService.createEntitiesIfNeeded(
176-
workflowRuntimeData.context.entity.data.additionalInfo.directors || [],
177-
tokenScope.projectId,
178-
transaction,
179-
);
180-
181-
const ubos = await this.collectionFlowService.createEntitiesIfNeeded(
182-
workflowRuntimeData.context.entity.data.additionalInfo.ubos || [],
183-
tokenScope.projectId,
184-
transaction,
185-
);
186-
187-
await this.collectionFlowStateService.updateCollectionFlowState(
188-
tokenScope.workflowRuntimeDataId,
189-
{
190-
...((body.context.collectionFlow as AnyRecord).state as TCollectionFlowState),
191-
steps: (
192-
(body.context.collectionFlow as AnyRecord).state as TCollectionFlowState
193-
).steps.map((step: TCollectionFlowStep) => ({
194-
...step,
195-
state: CollectionFlowStepStatesEnum.completed,
196-
})),
197-
status: CollectionFlowStatusesEnum.completed,
198-
},
199-
[tokenScope.projectId],
200-
transaction,
201-
);
202-
203-
await this.workflowService.event(
204-
{
205-
id: tokenScope.workflowRuntimeDataId,
206-
name: BUILT_IN_EVENT.DEEP_MERGE_CONTEXT,
207-
payload: {
208-
newContext: {
209-
entity: {
210-
data: {
211-
additionalInfo: {
212-
directors: directors?.length ? directors : undefined,
213-
ubos: ubos?.length ? ubos : undefined,
214-
},
215-
},
216-
},
217-
},
218-
arrayMergeOption: ARRAY_MERGE_OPTION.REPLACE,
219-
},
220-
},
221-
[tokenScope.projectId],
222-
tokenScope.projectId,
223-
transaction,
224-
);
225-
226-
await this.workflowService.event(
227-
{
228-
id: tokenScope.workflowRuntimeDataId,
229-
name: body.eventName,
230-
},
231-
[tokenScope.projectId],
232-
tokenScope.projectId,
233-
transaction,
234-
);
160+
await this.collectionFlowStateService.updateCollectionFlowState(
161+
tokenScope.workflowRuntimeDataId,
162+
{
163+
...((body.context.collectionFlow as AnyRecord).state as TCollectionFlowState),
164+
steps: (
165+
(body.context.collectionFlow as AnyRecord).state as TCollectionFlowState
166+
).steps.map((step: TCollectionFlowStep) => ({
167+
...step,
168+
state: CollectionFlowStepStatesEnum.completed,
169+
})),
170+
status: CollectionFlowStatusesEnum.completed,
171+
},
172+
[tokenScope.projectId],
173+
);
235174

236-
return await this.workflowService.event(
237-
{
238-
id: tokenScope.workflowRuntimeDataId,
239-
name: BUILT_IN_EVENT.DEEP_MERGE_CONTEXT,
240-
payload: {
241-
newContext: body.context,
242-
arrayMergeOption: ARRAY_MERGE_OPTION.REPLACE,
243-
},
175+
await this.workflowService.event(
176+
{
177+
id: tokenScope.workflowRuntimeDataId,
178+
name: body.eventName,
179+
},
180+
[tokenScope.projectId],
181+
tokenScope.projectId,
182+
);
183+
184+
return await this.workflowService.event(
185+
{
186+
id: tokenScope.workflowRuntimeDataId,
187+
name: BUILT_IN_EVENT.DEEP_MERGE_CONTEXT,
188+
payload: {
189+
newContext: body.context,
190+
arrayMergeOption: ARRAY_MERGE_OPTION.REPLACE,
244191
},
245-
[tokenScope.projectId],
246-
tokenScope.projectId,
247-
transaction,
248-
);
249-
});
192+
},
193+
[tokenScope.projectId],
194+
tokenScope.projectId,
195+
);
250196
} catch (error) {
251197
if (error instanceof CollectionFlowMissingException) {
252198
throw error;

services/workflows-service/src/collection-flow/services/collection-flow.service.ts

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -227,41 +227,4 @@ export class CollectionFlowService {
227227
{ shouldDownloadFromSource: false },
228228
);
229229
}
230-
231-
async createEntitiesIfNeeded(
232-
entities: Array<{
233-
firstName: string;
234-
lastName: string;
235-
email: string;
236-
ballerineEntityId?: string;
237-
}>,
238-
projectId: string,
239-
transaction: Prisma.TransactionClient,
240-
) {
241-
const createdEntities = entities.map(async entity => {
242-
// If ID is present then entity been created in KYB
243-
if (entity.ballerineEntityId) {
244-
return entity;
245-
}
246-
247-
const { id } = await this.endUserService.create(
248-
{
249-
data: {
250-
firstName: entity.firstName,
251-
lastName: entity.lastName,
252-
email: entity.email,
253-
projectId,
254-
},
255-
},
256-
transaction,
257-
);
258-
259-
return {
260-
ballerineEntityId: id,
261-
...entity,
262-
};
263-
});
264-
265-
return await Promise.all(createdEntities);
266-
}
267230
}

0 commit comments

Comments
 (0)