I'm facing a challenge with refactoring duplicated code in my project and I'm not sure where to start.
There are two methods in my code that essentially perform the same task by calling the same service (due to pagination requirements), but this repetition is making it messy. How can I improve this situation?
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
};
})
);