Skip to content
Snippets Groups Projects
Commit 5a7f24b3 authored by elit04's avatar elit04
Browse files

create log entry controller

parent df23fd02
No related branches found
No related tags found
No related merge requests found
...@@ -2,8 +2,11 @@ import bcrypt from "bcrypt"; ...@@ -2,8 +2,11 @@ import bcrypt from "bcrypt";
import { Request, Response } from "express"; import { Request, Response } from "express";
import jwt from "jsonwebtoken"; import jwt from "jsonwebtoken";
import Employee from "../db/models/Employee"; import Employee from "../db/models/Employee";
import CheckIn from "../db/models/CheckIn";
import Boat from "../db/models/Boat";
import envVars from "../config"; import envVars from "../config";
//log in
const authLoginController = async (req: Request, res: Response) => { const authLoginController = async (req: Request, res: Response) => {
try { try {
const { email, password } = req.body; const { email, password } = req.body;
...@@ -38,4 +41,51 @@ const authLoginController = async (req: Request, res: Response) => { ...@@ -38,4 +41,51 @@ const authLoginController = async (req: Request, res: Response) => {
return res.status(500).json({ success: false, error: "serverError" }); return res.status(500).json({ success: false, error: "serverError" });
} }
}; };
export default authLoginController;
//create log entry
const createLogEntry = async (req: Request, res: Response) => {
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" });
}
};
const authControllers = {
authLoginController,
createLogEntry,
};
export default authControllers;
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