-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Stephanie Chan edited this page Jan 13, 2018
·
3 revisions
Welcome to the sasc wiki!
This is where all of the database access methods are being placed. There are three rules for implementing these methods:
- Each method should only ever make one asynchronous call.
- Each method should take two parameters: an object with fields that need to be entered into the database and a callback.
- The callback should be invoked at the end of the method, regardless of whether an error occurred or not. The reason why we don't want the models to know about the request (eg. req.body.username, ... etc.) is that we don't want models to break every time we alter the schema or change code on the client-side. The models are also not responsible for sending the response, which will be handled by the controllers. This is because we need to tailor our responses according to the changes made. For example, if the user is updating their profile information, they should get different success and error messages versus updating their password, even though the same update method from models is being called. Logic in models should be kept as simple as possible to ensure they can be used everywhere. Refer to the folder client/src/Redux/Actions to find action files where a controller's corresponding frontend API call will be written.
This is where all the backend logic or processing should be placed. Controllers are the bridge between models and routes. They have access to request and response objects through their parameters. If you are writing a controller, you need to know what is being passed into the request object on the frontend and the response the frontend expects. Backend form validation, regex checks, field trimming, and calls to database access methods are done here.
The routes have the URI and type of request (eg. GET, POST, etc.) that corresponds to its frontend API call. This is where controllers are called.