Initial commit

TODO: change api.conf URL references to use environment variables and add these variables to the docker-compose configuration for host domain
This commit is contained in:
2023-03-28 00:08:50 -07:00
parent 2d6d44b89f
commit 9f2473801c
82 changed files with 13974 additions and 1 deletions

View File

@@ -0,0 +1,95 @@
const rank = require("../controllers/Rank.controller.js");
const db = require("..");
var router = require("express").Router();
// Create a new Rank
router.post("/", rank.create);
// GET RANK
router.get("/", async (req, res) => {
const id = req.query.id;
if (!id) {
return db.Rank.findAll()
.then(results => res.send(results))
}
return db.Rank.findByPk(id)
.then(async (rank) => {
if (rank === null) {
res.status(404).send({
message: `Rank with id=${id} was not found!`
});
return
}
res.send(rank)
})
.catch(err => {
res.status(500).send({
message:
err.message || "Some error occurred while retrieving ranks."
})
})
});
// GET RANK DETAILS
router.get("/details", async (req, res) => {
const id = req.query.id;
if (!id) {
res.status(400).send({
message: "Rank id cannot be empty!"
});
return
}
return db.Rank.findByPk(id, {
include: [
'members',
]
})
.then(async (rank) => {
if (rank === null) {
res.status(404).send({
message: `Rank with id=${id} was not found!`
});
return
}
res.send(rank)
})
.catch(err => {
res.status(500).send({
message:
err.message || "Some error occurred while retrieving ranks."
})
})
});
// GET CATEGORIES
router.get("/categories", async (req, res) => {
return db.Rank.findAll({
attributes: ['category'],
group: ['category']
})
.then(async (rankCategories) => {
if (rankCategories === null) {
res.status(404).send({
message: `Rank categories were not found!`
});
return
}
res.send(rankCategories.map(rankCategory => rankCategory.category))
})
.catch(err => {
res.status(500).send({
message:
err.message || "Some error occurred while retrieving rank categories."
})
})
});
module.exports = {
apiPath: "/api/ranks",
apiRouter: router
};