Custom Code and Data
Here is a quick explanation of the different javascript code files and where to go to change things.
users.model.js
Contain the schema variables for the database.
If you want to add new values, you need to add them here inside the schema at the start of the file. For more information, check mongoose doc: https://mongoosejs.com/docs/guide.html
users.controller.js
Contains the code logic that happens when a request is called. Usually those functions will have a request and response as parameter and will call
To return the status code and json data to the client.
users.routes.js
contain all the requests definitions and comment on parameters they should have in the body or in
This functions defines the https://yourapi.com/users
request. And will return the list of all users.
Example of adding variables to the code
Let's say we want to add a description variable and a gem variable.
In the model.js file, add this inside the schema
The description is just some text the user can add to their account, since they are allowed to change it themselves, we will add it to the edit user function (where we change the avatar). The gems variable should not be edited by the users because it represent a currency they own, so only the server should be able to give it to users. For this reason we will add it to the rewards request.
users.controller.js, editUserAccount function
users.controller.js, gainReward function
In Unity, inside ApiMsg.cs you will need to edit the class EditUserRequest and GainRewardRequest to add the new variables.
Last updated