@@ -31,28 +31,38 @@ const deleteStep: MutationResolvers['deleteStep'] = async (
3131 // ** IMPORTANT NOTE **
3232 // We only support contiguous steps for now.
3333 //
34- if (
35- ! steps . every (
36- ( step , index ) =>
37- index === 0 || step . position === steps [ index - 1 ] . position + 1 ,
38- )
39- ) {
40- throw new Error ( 'Must delete contiguous steps!' )
41- }
34+ if ( steps . length === 1 && steps [ 0 ] . type === 'trigger' ) {
35+ await steps [ 0 ] . $query ( ) . patchAndFetch ( {
36+ key : null ,
37+ appKey : null ,
38+ connectionId : null ,
39+ parameters : { } ,
40+ status : 'incomplete' ,
41+ } )
42+ } else {
43+ if (
44+ ! steps . every (
45+ ( step , index ) =>
46+ index === 0 || step . position === steps [ index - 1 ] . position + 1 ,
47+ )
48+ ) {
49+ throw new Error ( 'Must delete contiguous steps!' )
50+ }
4251
43- const stepIds = steps . map ( ( step ) => step . id )
52+ const stepIds = steps . map ( ( step ) => step . id )
4453
45- /**
46- * NOTE: do not delete execution steps
47- * The deletion causes RDS CPU Utilisation to spike for high volume pipes.
48- */
49- // await Step.relatedQuery('executionSteps', trx).for(stepIds).delete()
50- await Step . query ( trx ) . findByIds ( stepIds ) . delete ( )
54+ /**
55+ * NOTE: do not delete execution steps
56+ * The deletion causes RDS CPU Utilisation to spike for high volume pipes.
57+ */
58+ // await Step.relatedQuery('executionSteps', trx).for(stepIds).delete()
59+ await Step . query ( trx ) . findByIds ( stepIds ) . delete ( )
5160
52- await steps [ 0 ] . flow
53- . $relatedQuery ( 'steps' , trx )
54- . where ( 'position' , '>' , steps [ steps . length - 1 ] . position )
55- . patch ( { position : raw ( `position - ${ steps . length } ` ) } )
61+ await steps [ 0 ] . flow
62+ . $relatedQuery ( 'steps' , trx )
63+ . where ( 'position' , '>' , steps [ steps . length - 1 ] . position )
64+ . patch ( { position : raw ( `position - ${ steps . length } ` ) } )
65+ }
5666
5767 return await steps [ 0 ] . flow
5868 . $query ( trx )
0 commit comments