Skip to content
Snippets Groups Projects
Commit 8d755bef authored by elit04's avatar elit04
Browse files

working create log entry route/controller

parent 304706c1
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
......@@ -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(),
......
......@@ -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
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