Skip to content
Snippets Groups Projects
Commit 2ba1a654 authored by alrwasheda's avatar alrwasheda :speech_balloon:
Browse files

exporting controller directly + some fixes

parent 983c582f
No related branches found
No related tags found
No related merge requests found
......@@ -3,44 +3,36 @@ import CheckIn from "../db/models/CheckIn";
import Boat from "../db/models/Boat";
//create log entry
const createLogEntry = async (req: Request, res: Response) => {
const createLogEntryController = async (req: Request, res: Response) => {
try {
const logEntry = req.body;
const boatid = await Boat.findByPk(logEntry.boatID);
try{
const logEntry = req.body;
const boatid = Boat.findByPk(logEntry.boatID);
//get status of boat
const bootAvailability = (await boatid).status;
//if boat is not available => it's locked
if(!(bootAvailability === true)) {
return res.status(409).json({ success: false, error: "BoatLocked" });
};
const newLogEntry = await CheckIn.create(logEntry);
return res.status(201).json({
success: true,
account: {
startTime: newLogEntry.startTime,
estimatedEndTime: newLogEntry.estimatedEndTime,
email: newLogEntry.email,
firstName: newLogEntry.firstName,
lastName: newLogEntry.lastName,
additionalClients: newLogEntry.additionalClients,
boatID: newLogEntry.boatID,
},
});
} catch (error) {
console.error(error.message);
return res.status(500).json({ success: false, error: "serverError" });
//get status of boat
const bootAvailability = boatid.status;
//if boat is not available => it's locked
if (bootAvailability === false) {
return res.status(409).json({ success: false, error: "BoatLocked" });
}
const newLogEntry = await CheckIn.create(logEntry);
return res.status(201).json({
success: true,
result: {
startTime: newLogEntry.startTime,
estimatedEndTime: newLogEntry.estimatedEndTime,
email: newLogEntry.email,
firstName: newLogEntry.firstName,
lastName: newLogEntry.lastName,
additionalClients: newLogEntry.additionalClients,
boatID: newLogEntry.boatID,
},
});
} catch (error) {
console.error(error.message);
return res.status(500).json({ success: false, error: "serverError" });
}
};
const createLogEntryControllers = {
createLogEntry,
};
export default createLogEntryControllers;
\ No newline at end of file
export default createLogEntryController;
import { Router } from "express";
import { body } from "express-validator";
import handleValidationResult from "../middleware/handleValidationResult";
import createLogEntryControllers from "../controllers/createLogEntryControllers.controllers";
import createLogEntryController from "../controllers/createLogEntryControllers.controllers";
const entryRouter = Router();
//create new log entry route
entryRouter.post(
"/api/logentry/",
//isISO8601() checks if string is a valid date+time
body("startTime").isISO8601(),
body("estimatedEndTime").isISO8601(),
body("email").isEmail().normalizeEmail(),
body("firstName").not().isEmpty(),
body("lastName").not().isEmpty(),
body("boatID").isUUID(),
handleValidationResult,
createLogEntryControllers.createLogEntry
);
"/api/logentry/",
//isISO8601() checks if string is a valid date+time
body("startTime").isISO8601(),
body("estimatedEndTime").isISO8601(),
body("email").isEmail().normalizeEmail(),
body("firstName").not().isEmpty(),
body("lastName").not().isEmpty(),
body("boatID").isUUID(),
handleValidationResult,
createLogEntryController
);
export default entryRouter;
\ No newline at end of file
export default entryRouter;
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