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"; ...@@ -6,7 +6,6 @@ import BoatType from "../db/models/BoatType";
//create log entry //create log entry
const createLogEntryController = async (req: Request, res: Response) => { const createLogEntryController = async (req: Request, res: Response) => {
try { try {
//get input //get input
const logEntryInput = req.body; const logEntryInput = req.body;
...@@ -31,27 +30,27 @@ const createLogEntryController = async (req: Request, res: Response) => { ...@@ -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) //check if number of additional clientsNames == given num of all clients - 1 (without responsible client)
const numOfAdditionalClients = logEntryInput.additionalClients.length; const numOfAdditionalClients = logEntryInput.additionalClients.length;
const numP = logEntryInput.numP; 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({ return res.status(404).json({
success: false, success: false,
error: "numberOfAllGivenClientsNamesDoesNotMatchNumberOfAllClients", error: "numberOfAllGivenClientsNamesDoesNotMatchNumberOfAllClients",
}); });
} }
//check of numOfAllClients >= minP && numOfAllClients <= maxP //check of numOfAllClients >= minP && numOfAllClients <= maxP
const minP = chosenBoat.minP; const minP = chosenBoat.minP;
const maxP = chosenBoat.maxP; const maxP = chosenBoat.maxP;
if (logEntryInput.numP >= minP && logEntryInput.numP <= maxP) { if (!(logEntryInput.numP >= minP && logEntryInput.numP <= maxP)) {
return res.status(404).json({ return res.status(404).json({
success: false, success: false,
error: "numberOfAllGivenClientsDoesNotMatchRequirementsOfChosenBoat", error:
"numberOfAllGivenClientsDoesNotMatchRequirementsOfChosenBoatSeatNumber",
}); });
} }
//create entry //create entry
const newLogEntry = await CheckIn.create(logEntryInput); const newLogEntry = await CheckIn.create(logEntryInput);
......
...@@ -55,7 +55,8 @@ export const initCheckIn = async (sequelizeConnection: Sequelize) => { ...@@ -55,7 +55,8 @@ export const initCheckIn = async (sequelizeConnection: Sequelize) => {
}, },
date: { date: {
type: DataTypes.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: { destination: {
type: DataTypes.STRING(), type: DataTypes.STRING(),
...@@ -89,11 +90,13 @@ export const initCheckIn = async (sequelizeConnection: Sequelize) => { ...@@ -89,11 +90,13 @@ export const initCheckIn = async (sequelizeConnection: Sequelize) => {
}, },
bookingType: { bookingType: {
type: DataTypes.STRING(), type: DataTypes.STRING(),
allowNull: false, // allowNull = true in order for the http request CheckIn to work
allowNull: true,
}, },
returned: { returned: {
type: DataTypes.BOOLEAN, type: DataTypes.BOOLEAN,
allowNull: false, // allowNull = true in order for the http request CheckIn to work
allowNull: true,
}, },
note: { note: {
type: DataTypes.STRING(), type: DataTypes.STRING(),
......
...@@ -16,10 +16,10 @@ entryRouter.post( ...@@ -16,10 +16,10 @@ entryRouter.post(
body("fullNameOfResponsibleClient").not().isEmpty(), body("fullNameOfResponsibleClient").not().isEmpty(),
body("boatId").isUUID(), body("boatId").isUUID(),
body("additionalClients").if(body("additionalClients").exists()).isArray(), body("additionalClients").if(body("additionalClients").exists()).isArray(),
body("totalNumberOfClients").isInt(), body("numP").isInt(),
body("note").if(body("note").exists()).isString(), body("note").if(body("note").exists()).isString(),
handleValidationResult, handleValidationResult,
createLogEntryController 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