Skip to content

Commit 4b8d1a2

Browse files
authored
Bal 4370 flaky plugin rerun during submission in edit (#3428)
* fix: fixed issue where edit status was updated to in progress (#3427) * feat: reworked final submission & added plugins output cleanup * fix: fixed types
1 parent a562137 commit 4b8d1a2

File tree

2 files changed

+45
-19
lines changed

2 files changed

+45
-19
lines changed

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

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
AnyRecord,
2020
CollectionFlowStatusesEnum,
2121
CollectionFlowStepStatesEnum,
22+
DefaultContextSchema,
2223
TCollectionFlowState,
2324
TCollectionFlowStep,
2425
} from '@ballerine/common';
@@ -157,38 +158,53 @@ export class CollectionFlowController {
157158
@common.Post('/final-submission')
158159
async finalSubmission(@TokenScope() tokenScope: ITokenScope, @common.Body() body: FinishFlowDto) {
159160
try {
160-
await this.collectionFlowStateService.updateCollectionFlowState(
161+
const { eventName, context } = body;
162+
163+
const collectionFlowState = (context.collectionFlow as AnyRecord)
164+
.state as TCollectionFlowState;
165+
166+
if (collectionFlowState?.status === CollectionFlowStatusesEnum.edit) {
167+
const pluginsOutput = this.collectionFlowService.removePluginsOutput({
168+
context: context as DefaultContextSchema,
169+
plugins: [
170+
'businessInformation',
171+
'companySanctions',
172+
'merchantScreening',
173+
'merchantMonitoring',
174+
'riskEvaluation',
175+
],
176+
});
177+
178+
context.pluginsOutput = pluginsOutput;
179+
}
180+
181+
await this.workflowService.updateWorkflowRuntimeData(
161182
tokenScope.workflowRuntimeDataId,
162183
{
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,
184+
context,
171185
},
172-
[tokenScope.projectId],
186+
tokenScope.projectId,
173187
);
174188

175-
await this.workflowService.event(
189+
await this.collectionFlowStateService.updateCollectionFlowState(
190+
tokenScope.workflowRuntimeDataId,
176191
{
177-
id: tokenScope.workflowRuntimeDataId,
178-
name: body.eventName,
192+
...((context.collectionFlow as AnyRecord).state as TCollectionFlowState),
193+
steps: ((context.collectionFlow as AnyRecord).state as TCollectionFlowState).steps.map(
194+
(step: TCollectionFlowStep) => ({
195+
...step,
196+
state: CollectionFlowStepStatesEnum.completed,
197+
}),
198+
),
199+
status: CollectionFlowStatusesEnum.completed,
179200
},
180201
[tokenScope.projectId],
181-
tokenScope.projectId,
182202
);
183203

184204
return this.workflowService.event(
185205
{
186206
id: tokenScope.workflowRuntimeDataId,
187-
name: BUILT_IN_EVENT.DEEP_MERGE_CONTEXT,
188-
payload: {
189-
newContext: body.context,
190-
arrayMergeOption: ARRAY_MERGE_OPTION.REPLACE,
191-
},
207+
name: eventName,
192208
},
193209
[tokenScope.projectId],
194210
tokenScope.projectId,

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,14 @@ export class CollectionFlowService {
227227
{ shouldDownloadFromSource: false },
228228
);
229229
}
230+
231+
removePluginsOutput({ context, plugins }: { context: DefaultContextSchema; plugins: string[] }) {
232+
const pluginsOutput = structuredClone(context.pluginsOutput || {});
233+
234+
plugins.forEach(pluginName => {
235+
delete pluginsOutput[pluginName as keyof typeof pluginsOutput];
236+
});
237+
238+
return pluginsOutput;
239+
}
230240
}

0 commit comments

Comments
 (0)