@@ -27,8 +27,6 @@ import * as common from '@nestjs/common';
2727import { ApiExcludeController } from '@nestjs/swagger' ;
2828import { CollectionFlowMissingException } from '../exceptions/collection-flow-missing.exception' ;
2929import { CollectionFlowStateService } from '../services/collection-flow-state.service' ;
30- import { defaultPrismaTransactionOptions } from '@/prisma/prisma.util' ;
31- import { beginTransactionIfNotExistCurry } from '@/prisma/prisma.util' ;
3230import { 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 ;
0 commit comments