import { BaseEntityModel } from '@gauzy/contracts' ; import { HttpClient } from '@angular/common/http' ; import { firstValueFrom } from 'rxjs' ; export abstract class Service < BE extends BaseEntityModel , FI = Partial < BE > , CI = Partial < BE > > { protected basePath : string ; protected http : HttpClient ; protected constructor ( { http , basePath } ) { this . basePath = basePath ; this . http = http ; } public create ( data ) { return firstValueFrom ( this . http . post < BE > ( this . basePath , data ) ) ; } public find < L extends { items : BE [ ] ; total : number ; } > ( ) ; public find ( id ) ; public find < L extends { items : BE [ ] ; total : number ; } > ( relations , filter ) ; public find < LBE extends { items : BE [ ] ; total : number ; } > ( idOrRelations ? , filter ? ) { if ( ! arguments . length ) { return firstValueFrom ( this . http . get < LBE > ( this . basePath ) ) ; } else if ( 'string' === typeof idOrRelations ) { return firstValueFrom ( this . http . get < BE > ( `${ this . basePath }/${ idOrRelations }` ) ) ; } return firstValueFrom ( this . http . get < LBE > ( this . basePath , { params : { data : JSON . stringify ( { relations : idOrRelations , filter } ) } } ) ) ; } public update ( id , data ) { return firstValueFrom ( this . http . put < BE > ( `${ this . basePath }/${ id }` , data ) ) ; } public delete ( id ) { return firstValueFrom ( this . http . delete ( `${ this . basePath }/${ id }` ) ) ; } }