import { TranslateService } from '@ngx-translate/core' ; import { PortalResources } from './portal-resources' ; export class ApiProxy { name : string ; matchCondition : MatchCondition = new MatchCondition ( ) ; backendUri : string ; requestOverrides ? : any ; responseOverrides ? : any ; public static fromJson ( obj ) { const result = [ ] ; const proxies = obj . proxies ; for ( const property in proxies ) { if ( proxies . hasOwnProperty ( property ) ) { const proxy = < ApiProxy > proxies [ property ] ; proxy . name = property ; result . push ( proxy ) ; } } return result ; } public static toJson ( proxies , ts ) { const cloneProxies = JSON . parse ( JSON . stringify ( proxies , ApiProxy . replacer ) ) ; const result = { } ; cloneProxies . forEach ( p => { if ( p . name !== ts . instant ( PortalResources . sidebar_newApiProxy ) ) { const name = p . name ; delete p . name ; if ( ! p . matchCondition . methods || p . matchCondition . methods . length === 0 ) { delete p . matchCondition . methods ; } result [ name ] = { } ; result [ name ] . matchCondition = p . matchCondition ; if ( p . backendUri ) { result [ name ] . backendUri = p . backendUri ; } for ( const prop in p ) { if ( prop !== 'matchCondition' && prop !== 'backendUri' ) { result [ name ] [ prop ] = p [ prop ] ; } } } } ) ; return JSON . stringify ( { $schema : 'http://json.schemastore.org/proxies' , proxies : result , } , null , 4 ) ; } private static replacer ( key , value ) { if ( key === 'functionApp' ) { return undefined ; } return value ; } } export class MatchCondition { methods : string [ ] ; route : string ; }