Initial commit

This commit is contained in:
root
2023-04-27 14:46:18 +00:00
commit bbca1a86d1
35 changed files with 2418 additions and 0 deletions
+84
View File
@@ -0,0 +1,84 @@
import routeObj from './../modules/dataObjects/route.js';
export const getRoute = (req, res) => {
const { id } = req.params;
const tempRoutes = global.routes;
for (var i = 0; i < tempRoutes.length; i++) {
if (tempRoutes[i].number == id) {
res.status(202).send(tempRoutes[i]);
return;
}
}
res.status(418).send({ message: 'ID was not found... :/'});
}
export const createRoute = (req, res) => {
const { number } = req.body;
const { amountPoints } = req.body;
const { points } = req.body;
if (!number) {
res.status(418).send({
message: 'No route Number was set... :/'});
return;
}
const tempRoutes = global.routes;
for (var i = 0; i < tempRoutes.length; i++) {
if (tempRoutes[i].number == number) {
res.status(419).send({
message: 'Id is already taken.'
});
return;
}
}
if (!amountPoints) {
res.status(418).send({ message: 'No amountPoints was set... :/'});
return;
}
var newRoute;
newRoute = new routeObj(number, amountPoints, points);
tempRoutes.push(newRoute);
global.routes = tempRoutes;
res.status(201).send(newRoute);
}
export const deleteRoute = (req, res) => {
const { id } = req.params;
const tempRoutes = global.routes;
for (var i = 0; i < tempRoutes.length; i++) {
if (tempRoutes[i].number == id) {
tempRoutes.splice(i, 1);
global.routes = tempRoutes;
res.status(202).send({ message: 'Delete successful.'});
return;
}
}
res.status(418).send({ message: 'ID was not found... :/'});
}
export const getAmountRoutes = (req,res) => {
const tempRoutes = global.routes;
const amount = tempRoutes.length;
res.status(202).send({ amount: amount});
}
export const getRouteInfos = (req, res) => {
const tempRoutes = global.routes;
var infoObj = {};
infoObj.amountRoutes = tempRoutes.length;
infoObj.routeNumber = [];
infoObj.routePointsAmount = [];
for (var i = 0; i < tempRoutes.length; i++) {
infoObj.routeNumber[i] = tempRoutes[i].number;
infoObj.routePointsAmount[i] = tempRoutes[i].amountPoints;
}
res.status(202).send({ infoObj });
}