import { Resource } from './Resource' ; import { IResourceAction , ResourceRequestMethod } from './Declarations' ; export function ResourceAction ( methodOptions ? ) { methodOptions = methodOptions || { } ; if ( methodOptions . method === undefined ) { methodOptions . method = ResourceRequestMethod . Get ; } return function ( target , propertyKey ) { ( < any > target ) [ propertyKey ] = function ( ... args ) : any { const callbacks = args . filter ( ( arg ) => typeof arg === 'function' ) ; const data = args . filter ( ( arg ) => typeof arg !== 'function' ) ; const body = data [ 0 ] ; const query = data [ 1 ] ; const params = data [ 2 ] ; const onSuccess = callbacks [ 0 ] ; const onError = callbacks [ 1 ] ; const actionOptions = { ... this . getResourceOptions ( ) , ... methodOptions } ; return this . $restAction ( { actionAttributes : { body , query , params , onSuccess , onError } , actionOptions } ) ; } ; } ; }