Skip to content
Snippets Groups Projects
Commit 6fae4ee7 authored by elit04's avatar elit04
Browse files

modifications

parent fbb3853a
No related branches found
No related tags found
No related merge requests found
Boot:
minP,maxP (ja)
BootsType:
id, name (ja)
- color (donnerstag, im Frontend random oder in der DB festlegen?)
BootHatBootType:
bootId,bootTypeId (primaryKeys) (ja)
checkIn:
-Token(GD von Kunde) oder Sicherheitsfrage ( donnerstag )
-müssen alle Boote in der Bootshalle ausgetragen werden könne
(ja)
-Art: wie wurde gebucht (ja)
-Datum
-Ziel: optional?
-numP (Alle Personen inkl. Verantwortliche)
-email: von der buchenden Person
-zurückgegeben: true/false
-Anmerkung: vor oder auch nach Fahrt
changes in Endpoints:
sequelize: init boatHasBoatType table()
createLogEntry: comparison
boat: created connection in boatHasBoatType table
boattype: show boatType by give boatId must be written again.
-----------------
19.01:
DB Sport BoatHasSport
BoatController
BoatRoutes : (fehlt) überpüfen ob SportsArrayElements UUID sind!!!!
index.ts (init-methods)
......@@ -24,31 +24,26 @@ const createBoat = async (req: Request, res: Response) => {
}
//check if name of boat already exists
if (!(newBoatInput.name === undefined)) {
const checkBoatName = await Boat.findOne({
where: {
name: newBoatInput.name,
},
});
if (!(checkBoatName === null)) {
return res
.status(400)
.json({ success: false, error: "boatNameAlreadyExists" });
}
const checkBoatName = await Boat.findOne({
where: {
name: newBoatInput.name,
},
});
if (!(checkBoatName === null)) {
return res
.status(400)
.json({ success: false, error: "boatNameAlreadyExists" });
}
//check if minP is bigger than maxP => error
if (
!(newBoatInput.minP === undefined) &&
!(newBoatInput.maxP === undefined)
) {
if (newBoatInput.minP > newBoatInput.maxP) {
return res.status(409).json({
success: false,
error: "maximumNumberOfSeatsMustBeBiggerOrEqualMinimalNumberOfSeats",
});
}
if (newBoatInput.minP > newBoatInput.maxP) {
return res.status(409).json({
success: false,
error: "maximumNumberOfSeatsMustBeBiggerOrEqualMinimalNumberOfSeats",
});
}
//check if given sport-ids can be found
......@@ -79,10 +74,7 @@ const createBoat = async (req: Request, res: Response) => {
//if there is a sport, which isn't in the database, we return an array with the names of the missing sports
if (check === false) {
return res.status(404).json({
success: false,
error: "The SportIDs: " + listIfNotFound + " cannotBeFound",
});
return res.status(404).json({ success: false, sports: listIfNotFound });
}
//create the boat
......@@ -335,9 +327,7 @@ const updateBoatById = async (req: Request, res: Response) => {
//if the updated-to-be sportid(sportids) doesn't exist
if (check === false) {
return res
.status(404)
.json({ success: false, sports: listIfNotFound });
return res.status(404).json({ success: false, sports: listIfNotFound });
}
//if sports Array is with valid id's, assign them to boat; create entry (boatid, each id of given sportIds) inf BoatHasSport table
for (let i = 0; i < listIfFound.length; i++) {
......
......@@ -242,36 +242,12 @@ const showSportByBoatId = async (req: Request, res: Response) => {
}
};
// is this controller needed?
const showSportBySportId = async (req: Request, res: Response) => {
try {
if (!(res.locals.user.role === "coordinator")) {
return res
.status(403)
.json({ success: false, error: "MustBeCoordinator" });
}
const givenId = req.params.id;
const sport = await Sport.findByPk(givenId);
if (sport) {
return res.status(200).json({
success: true,
result: { id: givenId, name: sport.name, color: sport.color },
});
}
return res.status(404).json({ success: false, error: "sportIdNotFound" });
} catch (error) {
console.error("server error: ", error.message);
return res.status(500).json({ success: false, error: "serverError" });
}
};
const sportControllers = {
createSportController,
showAllSports,
deleteSportById,
updateSportById,
showSportByBoatId,
showSportBySportId,
};
export default sportControllers;
......@@ -16,7 +16,7 @@ entryRouter.post(
body("fullNameOfResponsibleClient").not().isEmpty(),
body("boatId").isUUID(),
body("additionalClients").if(body("additionalClients").exists()).isArray(),
body("numP").isInt(),
body("numP").isInt(), //number of the total participants (fullNameOfResponsibleClient + additionalClients)
body("note").if(body("note").exists()).isString(),
handleValidationResult,
createLogEntryController
......
......@@ -7,11 +7,7 @@ import validateToken from "../middleware/validateToken";
const sportRouter = Router();
//show all sports
sportRouter.get(
"/api/sport/",
validateToken,
sportControllers.showAllSports
);
sportRouter.get("/api/sport/", validateToken, sportControllers.showAllSports);
//create a sport
sportRouter.post(
......@@ -27,7 +23,7 @@ sportRouter.post(
sportRouter.delete(
"/api/sport/:id",
validateToken,
sportControllers.deleteSportById,
sportControllers.deleteSportById
);
//update a sport
......@@ -47,16 +43,4 @@ sportRouter.get(
sportControllers.showSportByBoatId
);
/*
//maybe this route is not needed
//show specific sport by sport id
sportRouter.get(
"/api/sport/id/:id/",
validateToken,
sportControllers.showSportBySportId
)
*/
export default sportRouter;
\ No newline at end of file
export default sportRouter;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment