How to implement a generic/reusable function for multiple tables
I have two separate tables for article views and case views and currently have two backend endpoints to get the last viewed cases and articles:
The code is exactly the same for articlesViews (except it select 'articleId: articlesViews.articleId'), so the logic is duplicated for both functions. Instead I want to create a function which takes the table as a (generic) argument along with a column (in my case 'articleId' or 'caseId'). Can someone help me with this?
I already tried it like shown below but i could't figure out the type for 'idColumn' and of course got an error for 'table[idColumn]'.
Thanks in advance 🙏🏼
1 Reply
one option would be pass the select as whole