From 8d755befd46a6488d3684c7385c7f0cc292102a9 Mon Sep 17 00:00:00 2001 From: elit04 <elit04@fu-berlin.de> Date: Sun, 23 Jan 2022 08:05:54 -0500 Subject: [PATCH] working create log entry route/controller --- .../src/controllers/createLogEntry.controllers.ts | 15 +++++++-------- server/src/db/models/CheckIn.ts | 9 ++++++--- server/src/routes/createLogEntry.routes.ts | 4 ++-- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/server/src/controllers/createLogEntry.controllers.ts b/server/src/controllers/createLogEntry.controllers.ts index 2ebb3e0..b16a20d 100644 --- a/server/src/controllers/createLogEntry.controllers.ts +++ b/server/src/controllers/createLogEntry.controllers.ts @@ -6,7 +6,6 @@ import BoatType from "../db/models/BoatType"; //create log entry const createLogEntryController = async (req: Request, res: Response) => { try { - //get input const logEntryInput = req.body; @@ -31,27 +30,27 @@ const createLogEntryController = async (req: Request, res: Response) => { //check if number of additional clientsNames == given num of all clients - 1 (without responsible client) const numOfAdditionalClients = logEntryInput.additionalClients.length; const numP = logEntryInput.numP; - - if (numOfAdditionalClients !== numP-1) { //-1 because of the responsible Person + + if (numOfAdditionalClients !== numP - 1) { + //-1 because of the responsible Person return res.status(404).json({ success: false, error: "numberOfAllGivenClientsNamesDoesNotMatchNumberOfAllClients", }); } - + //check of numOfAllClients >= minP && numOfAllClients <= maxP const minP = chosenBoat.minP; const maxP = chosenBoat.maxP; - if (logEntryInput.numP >= minP && logEntryInput.numP <= maxP) { + if (!(logEntryInput.numP >= minP && logEntryInput.numP <= maxP)) { return res.status(404).json({ success: false, - error: "numberOfAllGivenClientsDoesNotMatchRequirementsOfChosenBoat", + error: + "numberOfAllGivenClientsDoesNotMatchRequirementsOfChosenBoatSeatNumber", }); } - - //create entry const newLogEntry = await CheckIn.create(logEntryInput); diff --git a/server/src/db/models/CheckIn.ts b/server/src/db/models/CheckIn.ts index d27f787..e642337 100644 --- a/server/src/db/models/CheckIn.ts +++ b/server/src/db/models/CheckIn.ts @@ -55,7 +55,8 @@ export const initCheckIn = async (sequelizeConnection: Sequelize) => { }, date: { type: DataTypes.DATE, - allowNull: false, + // allowNull = true in order for the http request CheckIn to work, maybe needs to be entered/calculated automatically + allowNull: true, }, destination: { type: DataTypes.STRING(), @@ -89,11 +90,13 @@ export const initCheckIn = async (sequelizeConnection: Sequelize) => { }, bookingType: { type: DataTypes.STRING(), - allowNull: false, + // allowNull = true in order for the http request CheckIn to work + allowNull: true, }, returned: { type: DataTypes.BOOLEAN, - allowNull: false, + // allowNull = true in order for the http request CheckIn to work + allowNull: true, }, note: { type: DataTypes.STRING(), diff --git a/server/src/routes/createLogEntry.routes.ts b/server/src/routes/createLogEntry.routes.ts index ee8d60b..037bcdc 100644 --- a/server/src/routes/createLogEntry.routes.ts +++ b/server/src/routes/createLogEntry.routes.ts @@ -16,10 +16,10 @@ entryRouter.post( body("fullNameOfResponsibleClient").not().isEmpty(), body("boatId").isUUID(), body("additionalClients").if(body("additionalClients").exists()).isArray(), - body("totalNumberOfClients").isInt(), + body("numP").isInt(), body("note").if(body("note").exists()).isString(), handleValidationResult, createLogEntryController ); -export default entryRouter; +export default entryRouter; \ No newline at end of file -- GitLab