I need to refactor duplicated code but I don't know how I would do it.
I have two methods that basically call the same service (I need to call the same request because of pagination) but now it looks ugly because of duplicated code. How can I make this better?
getStockData(id: string): Observable<{
searchResult: IStockResult[];
searchCount: number;
}> {
return this.service
.search(
id,
this.service.getSearchMetaDefaults()
)
.pipe(
map(response => {
return {
searchResult: response,
searchCount: response.meta.totalResourceCount
};
})
);