11import { FlowApprovalApi , State } from "@/components/flow-approval/typings" ;
22import { FormActionContext } from "@flow-engine/flow-types" ;
3+ import { GroovyScriptConvertorUtil } from "@flow-engine/flow-core" ;
34
45export class FlowActionPresenter {
56
67 private readonly api : FlowApprovalApi ;
7- private readonly formActionContext :FormActionContext ;
8+ private readonly formActionContext : FormActionContext ;
89 private state : State ;
910
1011 constructor ( state : State ,
1112 api : FlowApprovalApi ,
12- formActionContext :FormActionContext ) {
13+ formActionContext : FormActionContext ) {
1314 this . state = state ;
1415 this . api = api ;
1516 this . formActionContext = formActionContext ;
@@ -19,7 +20,7 @@ export class FlowActionPresenter {
1920 this . state = state ;
2021 }
2122
22- public async processNodes ( ) {
23+ public async processNodes ( ) {
2324 const formData = this . formActionContext . save ( ) ;
2425 const id = this . state . flow ?. recordId || this . state . flow ?. workId || '' ;
2526 return await this . api . processNodes ( {
@@ -34,38 +35,40 @@ export class FlowActionPresenter {
3435 * @param actionId
3536 * @private
3637 */
37- private isPassAction ( actionId :string ) {
38+ private isPassAction ( actionId : string ) {
3839 const actions = this . state . flow ?. actions || [ ] ;
39- for ( const action of actions ) {
40- if ( action . id === actionId ) {
41- if ( action . type === 'PASS' ) {
40+ for ( const action of actions ) {
41+ if ( action . id === actionId ) {
42+ if ( action . type === 'PASS' ) {
4243 return true ;
4344 }
44- if ( action . type === 'CUSTOM' ) {
45+ if ( action . type === 'CUSTOM' ) {
4546 const script = action . script || '' ;
46-
47-
47+ const returnData = GroovyScriptConvertorUtil . getReturnScript ( script ) ;
48+ if ( returnData . includes ( 'PASS' ) ) {
49+ return true ;
50+ }
4851 }
4952 }
5053 }
5154 return false ;
5255 }
5356
5457
55- private async submitAction ( actionId :string , formData :any , params ?:any ) {
58+ private async submitAction ( actionId : string , formData : any , params ?: any ) {
5659 const recordId = this . state . flow ?. recordId ;
5760 const workId = this . state . flow ?. workId ;
58- if ( recordId ) {
61+ if ( recordId ) {
5962 const request = {
6063 formData,
6164 recordId,
62- advice :{
65+ advice : {
6366 actionId,
6467 ...params
6568 }
6669 }
6770 return await this . api . action ( request ) ;
68- } else {
71+ } else {
6972 const createRequest = {
7073 workId,
7174 formData,
@@ -75,7 +78,7 @@ export class FlowActionPresenter {
7578 const actionRequest = {
7679 formData,
7780 recordId,
78- advice :{
81+ advice : {
7982 actionId,
8083 ...params
8184 }
@@ -85,14 +88,14 @@ export class FlowActionPresenter {
8588 }
8689
8790
88- public async action ( actionId :string , params ?:any ) {
91+ public async action ( actionId : string , params ?: any ) {
8992 let formData ;
90- if ( this . isPassAction ( actionId ) ) {
93+ if ( this . isPassAction ( actionId ) ) {
9194 formData = await this . formActionContext . validate ( ) ;
92- } else {
95+ } else {
9396 formData = this . formActionContext . save ( ) ;
9497 }
95- return await this . submitAction ( actionId , formData , params ) ;
98+ return await this . submitAction ( actionId , formData , params ) ;
9699 }
97100
98101}
0 commit comments