Skip to content

Commit

Permalink
EJS implementation on the user's card in shiftTracker
Browse files Browse the repository at this point in the history
  • Loading branch information
HTSagara committed Apr 16, 2024
1 parent 5cd0970 commit 9e2c240
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
7 changes: 1 addition & 6 deletions modules/data-service.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
client,
dbName,
collectionName,
connectToDatabase,
} from "./database.js";
import { client, dbName, collectionName } from "./database.js";

// Call the connectToDatabase function to establish the connection
// connectToDatabase();
Expand Down
19 changes: 14 additions & 5 deletions routes/root.js → routes/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import {
createUser,
getUserByEmail,
getUserByName,
getUserBySin,
} from "../modules/data-service-auth.js";
import jwt from "jsonwebtoken";
import cookieParser from "cookie-parser";
import { requireAuth } from "../middleware/authMiddleware.js";
import { checkUser } from "../middleware/authMiddleware.js";

const router = express.Router();
const currentDir = process.cwd();
Expand Down Expand Up @@ -57,7 +58,7 @@ router.post("/create-user", async (req, res) => {
}
});

router.post("/shift-table", async (req, res) => {
router.post("/shift-tracker", async (req, res) => {
const { email, password } = req.body;

try {
Expand All @@ -74,7 +75,7 @@ router.post("/shift-table", async (req, res) => {
const token = createToken(user._id);
res
.cookie("jwt", token, { httpOnly: true, maxAge: maxAge * 1000 })
.sendFile(path.resolve(currentDir, "views", "shiftTracker.html"));
.sendFile(path.resolve(currentDir, "views", "shiftTracker.ejs"));
} else {
res.status(401).json({ message: "Invalid password" });
}
Expand Down Expand Up @@ -117,8 +118,16 @@ router.get("/logout", (req, res) => {
res.cookie("jwt", "", { maxAge: 1 }).redirect("/");
});

router.get("/shift-tracker", requireAuth, (req, res) => {
res.sendFile(path.resolve(currentDir, "views", "shiftTracker.html"));
router.get("/shift-tracker", checkUser, async (req, res) => {
// res.sendFile(path.resolve(currentDir, "views", "shiftTracker.ejs"));
const userId = res.locals.user._id;
const userInfo = await getUserBySin(client, userId);
console.log(JSON.stringify(userInfo));
res.render(path.resolve(currentDir, "views", "shiftTracker.ejs"), {
userName: userInfo.fullname,
userEmail: userInfo.email,
userPhone: userInfo.phone,
});
});

router.use("/record", timeRouter);
Expand Down
8 changes: 4 additions & 4 deletions routes/timeRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ timeRouter.post("/time-in", checkUser, async (req, res) => {
const lastShift = await checkLastShift(client, userId);
if (lastShift) {
console.log(`Last shift ${lastShift}`);
if (lastShift.workedHours === undefined) {
if (lastShift.shift.workedHours === undefined) {
console.log(`Last shift worked hours ${lastShift.workedHours}`);
return res
.status(400)
Expand Down Expand Up @@ -114,13 +114,13 @@ timeRouter.post("/time-out", checkUser, async (req, res) => {

const lastShift = await checkLastShift(client, userId);

if (!lastShift || lastShift.timeOutNum) {
if (!lastShift || lastShift.shift.timeOutNum) {
return res.status(400).json({
message: "Please start a new shift",
});
} else if (
lastShift.breakInNum != undefined &&
lastShift.breakOutNum === undefined
lastShift.shift.breakInNum != undefined &&
lastShift.shift.breakOutNum === undefined
) {
return res
.status(400)
Expand Down
3 changes: 1 addition & 2 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import express from "express";
import session from "express-session";
import path from "path";
import router from "./routes/root.js";
import router from "./routes/routes.js";
import {
client,
connectToDatabase,
Expand Down
12 changes: 6 additions & 6 deletions views/shiftTracker.html → views/shiftTracker.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
<div class="header">
<div class="left-box">
<img src="/pictures/waiter.png" alt="" />
<button id="usernameButton"><p>Evrim Ciftci</p></button>
<button id="usernameButton"><p><%= userName %></p></button>
<div id="userInfoBox">
<div class="companyInfo">
<span id="company">Company: CoffeeCollab </span>
<span id="manager">Manager: Henrique sagara </span>
<!-- <span id="manager">Manager: Henrique sagara </span> -->
</div>
<div class="userInfo">
<span id="firstName">First Name: Evrim </span>
<span id="lastName">Last Name: Ciftci </span>
<span id=" email">email: [email protected] </span>
<span id="phoneNumber">Phone Number: +1 6558 5885 58 </span>
<span id="firstName">Name: <%=userName%> </span>
<!-- <span id="lastName">Last Name: Ciftci </span> -->
<span id=" email">email: <%=userEmail%> </span>
<span id="phoneNumber">Phone Number: <%= userPhone%> </span>
</div>
</div>
</div>
Expand Down

0 comments on commit 9e2c240

Please sign in to comment.