import { HttpErrorResponse } from '@angular/common/http' ; import { Observable , throwError } from 'rxjs' ; import { catchError } from 'rxjs/operators' ; import { ODataCollection } from '../models/collection' ; import { ODataModel } from '../models/model' ; import { EntityKey , ODataEntities , ODataEntity , ODataEntityResource , ODataEntitySetResource , ODataOptions , } from '../resources' ; import { ODataEntityService } from './entity' ; export class ODataEntitySetService < T > extends ODataEntityService < T > { /**
     * Get the entity set resource for this service.
     */ public entities ( ) { return this . client . entitySet < T > ( this . name , this . apiNameOrEntityType ) ; } param key public entity ( key ? ) { return this . entities ( ) . entity ( key ) ; } param model public attach < M extends ODataModel < T > > ( model ) ; public attach < C extends ODataCollection < T , ODataModel < T > > > ( model ) ; public attach ( model ) { if ( model instanceof ODataModel ) { model . attach ( this . entities ( ) . entity ( ) ) ; } else if ( model instanceof ODataCollection ) { model . attach ( this . entities ( ) ) ; } } /**
     * The schema for the entity set.
     */ get entitySetSchema ( ) { return this . api . findEntitySetByName ( this . name ) ; } param options public fetchAll ( options ? ) { return this . entities ( ) . fetchAll ( options ) ; } param withCount param options public fetchMany ( options ? ) { return this . entities ( ) . fetch ( options ) ; } param key param etag param options public fetchOne ( key , options ? ) { return this . entity ( key ) . fetch ( options ) ; } param attrs param options public create ( attrs , options ? ) { return this . entities ( ) . create ( attrs , options ) ; } param key param attrs param etag param options public update ( key , attrs , options ? ) { const res = this . entity ( key ) ; if ( ! res . hasKey ( ) ) return throwError ( 'Resource without key' ) ; return res . update ( attrs , options ) ; } param key param attrs param etag param options public modify ( key , attrs , options ? ) { const res = this . entity ( key ) ; if ( ! res . hasKey ( ) ) return throwError ( 'Resource without key' ) ; return res . modify ( attrs , options ) ; } param key param etag param options public destroy ( key , options ? ) { const res = this . entity ( key ) ; if ( ! res . hasKey ( ) ) return throwError ( 'Resource without key' ) ; return res . destroy ( options ) ; } param key param attrs param etag param options public fetchOrCreate ( key , attrs , { etag , ... options } = { } ) { return this . fetchOne ( key , { etag , ... options } ) . pipe ( catchError ( ( error ) => { if ( error . status === 404 ) return this . create ( attrs , options ) ; else return throwError ( error ) ; } ) ) ; } param attrs param method param etag param options public save ( attrs , { etag , method , ... options } = { } ) { let schema = this . structuredTypeSchema ; if ( method === undefined && schema !== undefined && schema . isCompoundKey ( ) ) return throwError ( 'Composite key require a specific method, use create/update/patch' ) ; let key = schema && schema . resolveKey ( attrs ) ; if ( method === undefined ) method = key !== undefined ? 'update' : 'create' ; if ( ( method === 'update' || method === 'modify' ) && key === undefined ) return throwError ( "Can't update/patch entity without key" ) ; return method === 'create' ? this . create ( attrs , options ) : method === 'modify' ? this . modify ( key , attrs , { etag , ... options } ) : this . update ( key , attrs , { etag , ... options } ) ; } }