File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
packages/backend/src/apps/formsg/triggers/new-submission Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import { createMrfSteps } from './create-mrf-steps'
1313import { fetchFormSchema } from './fetch-form-schema'
1414import getMockData from './get-mock-data'
1515import { parseWorkflowData } from './get-workflow-data'
16+ import { removeMrfSteps } from './remove-mrf-steps'
1617
1718const formsgTestRunMetadataSchema = z
1819 . object ( {
@@ -114,6 +115,9 @@ const trigger: IRawTrigger = {
114115 // Create MRF steps for multirespondent forms
115116 const mrfWorkflowData = await parseWorkflowData ( $ , formSchema )
116117 await createMrfSteps ( $ , mrfWorkflowData )
118+ } else {
119+ // remove mrf object from parameters and remove mrf steps (if any)
120+ await removeMrfSteps ( $ )
117121 }
118122
119123 // if test with mock data is selected OR no past submission exists
Original file line number Diff line number Diff line change 1+ import { IGlobalVariable } from '@plumber/types'
2+
3+ import StepError from '@/errors/step'
4+ import Step from '@/models/step'
5+
6+ export async function removeMrfSteps ( $ : IGlobalVariable ) {
7+ if ( ! $ . flow ?. id || ! $ . step ?. id ) {
8+ throw new StepError (
9+ 'Missing flow or step' ,
10+ 'This should not happen, please contact support.' ,
11+ $ . step . position ,
12+ $ . app . name ,
13+ )
14+ }
15+
16+ await Step . transaction ( async ( trx ) => {
17+ // delete all mrf action steps
18+ await Step . query ( trx )
19+ . where ( 'flow_id' , $ . flow . id )
20+ . where ( 'type' , 'action' )
21+ . where ( 'key' , 'mrfSubmission' )
22+ . delete ( )
23+
24+ // reset trigger step parameters
25+ await Step . query ( trx )
26+ . where ( 'flow_id' , $ . flow . id )
27+ . where ( 'type' , 'trigger' )
28+ . where ( 'key' , 'newSubmission' )
29+ . patch ( {
30+ parameters : { } ,
31+ } )
32+ } )
33+ }
You can’t perform that action at this time.
0 commit comments