0

I wonder how can send the default data already in getWithQuery(), like this:

@Injectable({providedIn: 'root'})
export class CompaniesDataService extends DefaultDataService<Company> {
    private readonly _URL: string = '/api/companies';
    private readonly _DEFAULT_QUERIES: QueryParams = {top: '0', limit: '10', order: "name"};

    constructor(http: HttpClient, httpUrlGenerator: HttpUrlGenerator) {
        super('Company', http, httpUrlGenerator);
    }

    getWithQuery(queryParams: QueryParams | string = this._DEFAULT_QUERIES): Observable<Company[]> {
        return this.http
            .post<FmsHttpResponse<Company>>(`${this._URL}/search`, queryParams)
            .pipe(map(response => response.content));
    }
}

I mean this._DEFAULT_QUERIES pass as default queryParams in getWithQuery().

When I add function with resolver like this:

    return this.companyEntityService.getWithQuery()
      .pipe(tap(() => this.companyEntityService.setLoaded(true)));

I got error: Expected 1-2 arguments, but got 0..

Any idea? I would like to add that I am a novice ngrx programmer and maybe it is a simple question and I cannot find the answer.

Ania
  • 292
  • 4
  • 11

1 Answers1

-1

Why do you have to send something that is already in the class as a parameter? Why not do something like this:

 getWithQuery(queryParams: QueryParams | undefined): Observable<Company[]> {
       if(queryParams === undefined){
           queryParams = this._DEFAULT_QUERIES;
       }
        return this.http
            .post<FmsHttpResponse<Company>>(`${this._URL}/search`, queryParams)
            .pipe(map(response => response.content));
    }
Chimera
  • 149
  • 1
  • 13
  • No, it doesn't work like that. You have to override the `getWithQuery` function somehow – Ania Oct 20 '21 at 08:44
  • What do you mean by override? Do you have an error message? As far as i can see, it's a function that is used one or more places. So if you want to force it to use the _DEFAULT_QUERIES you just call it with getWithQuery(undefined) – Chimera Oct 21 '21 at 06:34