Skip to content

Development guide

Clément Roig edited this page May 26, 2022 · 20 revisions

Back-end (Sails) development

Adding a new route

When you need to write a new REST API route:

  1. Add the route to config/routes.js.
  2. Add the referred method to api/v1/xxxx/your-method.js with xxxx being the entity related to your method (cave, entrance, document, caver...)
  3. In the method, if needed, use the CheckRightService. ✳️ The returned result must be (almost) always formatted by the ControllerService treat and treatAndConvert methods. If you need to send a response before hitting the ControllerService, use the custom responses in the /api/responses folder (badRequest, notFound, ok and so on...) instead of using res.status() or res.send().
  4. Add the appropriate policy / policies to config/policies.js.
  5. If your method needs a database update (you need a new column or a new right for example), check if your local AND production databases are correctly set. ⚠️ Contact the Grottocenter administrators to update the production database: only them can do it!
  6. Add your new route to swaggerV1.yaml (you can use https://editor.swagger.io/ to edit it properly).
  7. Test, test and test your route, with correct data, with missing data, with invalid data etc. Add your test data to the sql/mock_data.sql file.
  8. Write tests in the test folder. Possibly, add mock data in .json fixtures files. You can take a look at the existing tests: a lots of typical cases are already covered for some resources (create, delete, find, findall, count...).

✳️ The rights management is detailed in the Grottocenter's Rights Management.

Useful Git commands

  • git rebase -i need to be used to group multiple "work in progress" commits into a single commit.

  • git remote prune origin to remove all branches in local that have been deleted on Github.

  • When the feature is ready you need to create a pull request on Github (https://github.com/GrottoCenter/Grottocenter3/pulls) : Let base: develop and compare: the branch.

  • Add a "Fix #1234" message with "1234" being the issue fixed by your PR in order to close it automatically when the PR is merged.

  • After the code review (which can include follow-up commits), the branch can be merged on develop with button "Merge pull request" ("Rebase and merge").

  • Don't forget to remove the remote branch after the merge