Best practice using PUT routes when updating the same table from different locations of the UI

Viewed 21

I understand that this question is very much opinion based however it would really help me to get some insight on how others structure their route/controller/query for their PUT requests around the same table.

My app has a client table. It has many columns; examples: is_active, agent_id. These columns of the same table are updated from various locations on the UI. My current approach is to write a route/controller/query for each transaction.

Example

1 Updating the status for a client

PUT Route: /api/client/[clientId]/status receives params from UI and passes them to controller =>

Controller: handleUpdateClientStatus passes params to query =>

Query: updateClientStatus (UPDATE client SET is_active = true WHERE id = 1)

2 Updating the agent id (FK to the agent table) for a client

PUT Route: /api/client/[clientId]/agent receives params from UI and passes them to controller =>

Controller: handleUpdateClientAgentId passes params to query =>

Query: updateClientAgentId (UPDATE client SET agent_id = 10 WHERE id = 1)

As you can see this seems cumbersome and there seems to be an opportunity to consolidate them but where & how? Should they all hit a generic PUT route (i.e. `/api/client) and if so should each update "instance" still have its own dedicated query that is then used by the controller based the incoming parameters?

0 Answers
Related