diff --git a/server/src/controllers/createLogEntry.controllers.ts b/server/src/controllers/createLogEntry.controllers.ts index 2ebb3e055307d003747478cf44e9afe45a6633c5..b16a20dd4cfa8f68f5e2158d205f94e089085267 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 d27f78774819129470f4b8284410111144469dd9..e6423376ece96f7211c80cb59f745649532d0202 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 ee8d60b672e0a1b2723133bfc8af7f781650f983..037bcdcef71f98350642a19efc87ccb65d84bb89 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