I'm curious about how to best manage an approval or rejection status update in my application. I have an endpoint that receives a status and I need to update it accordingly. Should I check the status in the application layer and call separate database functions for approving or rejecting, or is it better to handle everything in the database layer with a single function? Here's how I've outlined the two options:
**Option A – Application Layer Checks:**
- If the status is "approve", then call `db.approve(id)`.
- If it's "reject", call `db.reject(id)`.
- If the status is neither, return an error with a 422 status code.
**Option B – Single Database Function:**
- Check if the status is either "approve" or "reject" and call `db.resolveStatus({ id, decision: status })` for both.
- For any other status, return a 422 error.
Which approach do you guys think is more common or better?
2 Answers
Personally, I’d go with Option B but maybe rename it to `setStatus()`. It clearly conveys what the function does, encapsulating the logic for both approving and rejecting in one neat package!
Consider what you're trying to achieve with atomicity. If your operation is changing lots of things at once, it might need to happen in a transaction. Ultimately, think about what’s simpler and easier to maintain. Sometimes, breaking it out into separate functions for readability can be a great approach.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically