-
Notifications
You must be signed in to change notification settings - Fork 5
Responsibilities of Route functions vs DB methods
Route functions (functions that exist in files under /src/routes/
and are included in the ROUTES closure) serve to accept requests, validate that the user is able to perform the action, and then pass the validated request to the Database method(s).
The DB methods (methods that are attached to Identifiable
structs and live in /src/db/
) are responsible for executing DB queries/inserts/deletes/etc and formatting the result of those operations into arrangements that can be converted to the expected Response struct.
In regards to validation, the Route functions should validate user permissions (Is the user trying to edit this article the original author?), while the DB methods should ensure that the primary DB operation will not break the schema (Does the user_id for the author of this article exist? If I delete this user, make sure not to orphan associated data.)