@@ -17,6 +17,8 @@ import {RetrievalResponse} from "./response/RetrievalResponse";
1717
1818export class Builder < M extends Model = Model , GET_RESPONSE extends RetrievalResponse < M > = PluralResponse < M > > implements QueryMethods < M , GET_RESPONSE >
1919{
20+ protected readonly baseUrl : string ;
21+
2022 protected readonly modelType : any ;
2123
2224 private readonly httpClient : HttpClient ;
@@ -37,13 +39,13 @@ export class Builder<M extends Model = Model, GET_RESPONSE extends RetrievalResp
3739 forceSingular : boolean = false
3840 ) {
3941 this . modelType = modelType ;
40- let modelInstance : M = ( new ( < any > modelType ) ( ) ) ;
42+ this . baseUrl = modelType . effectiveJsonApiBaseUrl ;
4143 baseModelJsonApiType = baseModelJsonApiType
4244 ? baseModelJsonApiType
43- : modelInstance . getJsonApiType ( ) ;
45+ : modelType . effectiveJsonApiType ;
4446 this . query = new Query ( baseModelJsonApiType , queriedRelationName , baseModelJsonApiId ) ;
4547 this . initPaginationSpec ( ) ;
46- this . httpClient = modelType . getHttpClient ( ) ;
48+ this . httpClient = modelType . effectiveHttpClient ;
4749 this . forceSingular = forceSingular ;
4850 }
4951
@@ -53,7 +55,7 @@ export class Builder<M extends Model = Model, GET_RESPONSE extends RetrievalResp
5355 clone . getQuery ( ) . getPaginationSpec ( ) . setPage ( page ) ;
5456 if ( this . forceSingular ) {
5557 return this . getHttpClient ( )
56- . get ( clone . getQuery ( ) . toString ( ) )
58+ . get ( this . baseUrl + '/' + clone . getQuery ( ) . toString ( ) )
5759 . then (
5860 ( response : HttpClientResponse ) => {
5961 return new SingularResponse ( clone . getQuery ( ) , response , this . modelType , response . getData ( ) ) as unknown as GET_RESPONSE ;
@@ -64,7 +66,7 @@ export class Builder<M extends Model = Model, GET_RESPONSE extends RetrievalResp
6466 ) ;
6567 } else {
6668 return this . getHttpClient ( )
67- . get ( clone . getQuery ( ) . toString ( ) )
69+ . get ( this . baseUrl + '/' + clone . getQuery ( ) . toString ( ) )
6870 . then (
6971 ( response : HttpClientResponse ) => {
7072 return new PluralResponse ( clone . getQuery ( ) , response , this . modelType , response . getData ( ) , page ) as unknown as GET_RESPONSE ;
@@ -81,7 +83,7 @@ export class Builder<M extends Model = Model, GET_RESPONSE extends RetrievalResp
8183 const clone = this . clone ( ) ;
8284 clone . getQuery ( ) . getPaginationSpec ( ) . setPageLimit ( 1 ) ;
8385 return < Promise < SingularResponse < M > > > this . getHttpClient ( )
84- . get ( this . query . toString ( ) )
86+ . get ( this . baseUrl + '/' + clone . getQuery ( ) . toString ( ) )
8587 . then (
8688 ( response : HttpClientResponse ) => {
8789 return new SingularResponse ( this . query , response , this . modelType , response . getData ( ) ) ;
@@ -103,7 +105,7 @@ export class Builder<M extends Model = Model, GET_RESPONSE extends RetrievalResp
103105 const clone = this . clone ( ) ;
104106 clone . query . setIdToFind ( id ) ;
105107 return < Promise < SingularResponse < M > > > clone . getHttpClient ( )
106- . get ( clone . getQuery ( ) . toString ( ) )
108+ . get ( this . baseUrl + '/' + clone . getQuery ( ) . toString ( ) )
107109 . then (
108110 ( response : HttpClientResponse ) => {
109111 return new SingularResponse ( clone . getQuery ( ) , response , this . modelType , response . getData ( ) ) ;
@@ -163,7 +165,7 @@ export class Builder<M extends Model = Model, GET_RESPONSE extends RetrievalResp
163165 direction === SortDirection . ASC
164166 )
165167 ) ;
166-
168+
167169 return clone ;
168170 }
169171
@@ -218,15 +220,15 @@ export class Builder<M extends Model = Model, GET_RESPONSE extends RetrievalResp
218220 new OffsetBasedPaginationSpec (
219221 this . modelType . getPaginationOffsetParamName ( ) ,
220222 this . modelType . getPaginationLimitParamName ( ) ,
221- this . modelType . getPageSize ( )
223+ this . modelType . pageSize
222224 )
223225 ) ;
224226 } else if ( paginationStrategy === PaginationStrategy . PageBased ) {
225227 this . query . setPaginationSpec (
226228 new PageBasedPaginationSpec (
227229 this . modelType . getPaginationPageNumberParamName ( ) ,
228230 this . modelType . getPaginationPageSizeParamName ( ) ,
229- this . modelType . getPageSize ( )
231+ this . modelType . pageSize
230232 )
231233 ) ;
232234 } else {
0 commit comments