-
Notifications
You must be signed in to change notification settings - Fork 0
Technology Stack
Jake edited this page May 26, 2023
·
9 revisions
This section explains the technology used in the Major Manager Server and briefly shows how they are used
- Fast, unopinionated, minimalist web framework for Node.js
- Widely popular framework that is well tested and documented
- Express provides a middleware system that can be used to execute repeated functionality that occurs between receiving and handling requests. For example, when scores are uploaded for a particular Tournament, Express' middleware confirms that the User uploading the scores is logged in and has been assigned the role of
Admin
. If these checks both pass, we handle the POST request by executing theuploadPlayerScores
function (user.routes.js)
app.post(
'/api/v1/upload_player_scores/:id',
[authJwt.verifyToken, authJwt.isAdmin],
adminController.uploadPlayerScores,
);
- Routes, URL parameters and request payloads are easily defined, read and referenced with Express, which makes it ideal to use for building a RESTful API. The above POST request receives the id of the Tournament that is being updated as a parameter in the request URL via
:id
. This parameter can then be referenced in theuploadPlayerScores
function by callingreq.params.id
. The above request also receives a JSON object that is populated with Players scores. This data can be accessed via a reference toreq.body.playerData
as seen below (admin.controller.js).
exports.uploadPlayerScores = (req, res) => {
Admin.addPlayersToPlayersTable(req.body.playerData, (addPlayersErr, addPlayersData) => {
if (addPlayersErr) {
res.status(500).send({
message: 'Error uploading players to players table',
});
return;
}
Admin.addPlayersToTournamentTable(addPlayersData, req.params.id, req.body.round,
(addTournamentErr, addTournamentData) => {