@@ -44,7 +44,10 @@ export class ScenarioService {
4444 ) ;
4545 private gargAdmin = this . gcf . scopedClient ( '/a/scenario' ) ;
4646
47- constructor ( private gcf : GargantuaClientFactory , private http : HttpClient ) { }
47+ constructor (
48+ private gcf : GargantuaClientFactory ,
49+ private http : HttpClient ,
50+ ) { }
4851
4952 public watch ( ) {
5053 return this . bh . asObservable ( ) ;
@@ -115,7 +118,7 @@ export class ScenarioService {
115118 catchError ( ( e : HttpErrorResponse ) => {
116119 return throwError ( ( ) => e . error ) ;
117120 } ) ,
118- )
121+ ) ;
119122 }
120123
121124 public update ( s : Scenario ) {
@@ -126,6 +129,29 @@ export class ScenarioService {
126129 st . content = utoa ( st . content ) ;
127130 } ) ;
128131
132+ const normalizedVmTasks = ( s . vm_tasks ?? [ ] ) . map ( ( vmTaskGroup ) => ( {
133+ ...vmTaskGroup ,
134+ tasks : ( vmTaskGroup . tasks ?? [ ] ) . map ( ( task ) => {
135+ const rawExpectedReturnCode = ( task as any ) . expected_return_code ;
136+ let expectedReturnCode : number | null | undefined = undefined ;
137+ if (
138+ rawExpectedReturnCode === '' ||
139+ rawExpectedReturnCode === undefined ||
140+ rawExpectedReturnCode === null
141+ ) {
142+ expectedReturnCode = null ;
143+ } else if ( typeof rawExpectedReturnCode === 'number' ) {
144+ expectedReturnCode = rawExpectedReturnCode ;
145+ } else {
146+ const parsedReturnCode = parseInt ( String ( rawExpectedReturnCode ) , 10 ) ;
147+ expectedReturnCode = Number . isNaN ( parsedReturnCode )
148+ ? null
149+ : parsedReturnCode ;
150+ }
151+ return { ...task , expected_return_code : expectedReturnCode } ;
152+ } ) ,
153+ } ) ) ;
154+
129155 const params = new HttpParams ( { encoder : new CustomEncoder ( ) } )
130156 . set ( 'name' , utoa ( s . name ) )
131157 . set ( 'description' , utoa ( s . description ) )
@@ -135,7 +161,7 @@ export class ScenarioService {
135161 . set ( 'virtualmachines' , JSON . stringify ( s . virtualmachines ) )
136162 . set ( 'pause_duration' , s . pause_duration )
137163 . set ( 'keepalive_duration' , s . keepalive_duration )
138- . set ( 'vm_tasks' , JSON . stringify ( s . vm_tasks ) ) ;
164+ . set ( 'vm_tasks' , JSON . stringify ( normalizedVmTasks ) ) ;
139165
140166 return this . gargAdmin . put ( `/${ s . id } ` , params ) . pipe (
141167 tap ( ( ) => {
@@ -191,7 +217,9 @@ export class ScenarioService {
191217 }
192218
193219 public printable ( id : string ) {
194- return this . http . get ( `${ environment . server } /a/scenario/${ id } /printable` , { responseType : 'text' } ) ;
220+ return this . http . get ( `${ environment . server } /a/scenario/${ id } /printable` , {
221+ responseType : 'text' ,
222+ } ) ;
195223 }
196224
197225 public delete ( id : string ) {
0 commit comments