I am trying to figure out if there is a way to make my API request more flexible. I am passing params from my grid to by data service which has currently the below code. What I am trying to achieve is 2 things, one I am looking for a way which allows me to pass all params along without having to have them individually specified. Right now it will only pass the tags along but not the librarys as that param is not in the params list. Also I would like to avoid sending an empty query string if there is nothing specified for a params like tags, its present but if user does not select anything it will be empty array
This is a sample what params looks like
tags: []
librarys: ["Market Update"]
perPage: 100
offset: 0
__proto__: Object
thats the function code
getAllTemplates( params?: IGridDataFetcherParams) {
console.log(params)
return this.api.get({
endpoint: '/template/list',
params: {
rowCount: params.perPage,
offset: params.offset,
...(params.qsearch ? {qsearch: params.qsearch} : {} ),
...(params.tags && {tags: params.tags} ),
},
useAuthUrl: false,
}).pipe(
map(res => res as IApiResponseBody),
tap(res => console.log(res)),
);
}
Here is what my interface looks like
export interface IGridDataFetcherParams {
perPage?: string | number;
offset?: string | number;
qsearch?: string | number;
buckets?: string[];
bucket_group?: string[];
librarys?: string[];
tags?: string[];
type?: string;
tracts?: string[];
city?: string[],
email?: string,
phone?: string;
owner?: string;
qstype?: string;
}