import { Resource } from '../Resource' ; import { IResourceAction , IResourceResponse , ResourceActionReturnType , ResourceRequestMethod } from '../Declarations' ; export abstract class ResourceCRUDBase < TQuery , TShort , TFull , TQueryResult , TRetQuery , TRetFull , TRetAny > extends Resource { protected readonly abstract $crudReturnAs : ResourceActionReturnType ; query ( query ? , onSuccess ? , onError ? ) { return this . $restAction ( { actionAttributes : { body : query , onSuccess , onError } , actionOptions : this . $_crudBaseGetActionOptions ( ) } ) ; } get ( data , onSuccess ? , onError ? ) { return this . $restAction ( { actionAttributes : { body : data , onSuccess , onError } , actionOptions : this . $_crudBaseGetActionOptions ( { path : '/{!id}' } ) } ) ; } save ( data , onSuccess ? , onError ? ) { return this . $restAction ( { actionAttributes : { body : data , onSuccess , onError } , actionOptions : this . $_crudBaseGetActionOptions ( { method : ResourceRequestMethod . Post , } ) } ) ; } update ( data , onSuccess ? , onError ? ) { return this . $restAction ( { actionAttributes : { body : data , onSuccess , onError } , actionOptions : this . $_crudBaseGetActionOptions ( { method : ResourceRequestMethod . Put , path : '/{!id}' } ) } ) ; } remove ( data , onSuccess ? , onError ? ) { return this . $restAction ( { actionAttributes : { body : data , onSuccess , onError } , actionOptions : this . $_crudBaseGetActionOptions ( { method : ResourceRequestMethod . Delete , path : '/{!id}' } ) } ) ; } patch ( data , onSuccess ? , onError ? ) { return this . $restAction ( { actionAttributes : { body : data , onSuccess , onError } , actionOptions : this . $_crudBaseGetActionOptions ( { method : ResourceRequestMethod . Patch , path : '/{!id}' } ) } ) ; } create ( data , callback ? ) { return this . save ( data , callback ) ; } private $_crudBaseGetActionOptions ( actionOptions = { } ) { return { ... ( this as any ) . getResourceOptions ( ) , method : ResourceRequestMethod . Get , returnAs : this . $crudReturnAs , ... actionOptions } ; } }