Skip to content

Commit

Permalink
root.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Henrique Sagara authored and Henrique Sagara committed Feb 17, 2024
1 parent 3d1e03b commit 82c8b87
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
14 changes: 14 additions & 0 deletions routes/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// auth.js
import express from "express";
import { signup_get, signup_post, login_get, login_post } from "../controllers/authController.js";
import bcrypt from "bcrypt";
import jwt from "jsonwebtoken";

const router = express.Router();

router.get('/signup', signup_get);
router.post('/signup', signup_post);
router.get('/login', login_get);
router.post('/login', login_post);

export default router;
42 changes: 42 additions & 0 deletions routes/root.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import express from "express";
import path from "path";
import { client } from "../data-services/database.js";
import { timeIn, timeOut, deleteUserById, createUser } from "../data-services/data-service.js";

const router = express.Router();
const currentDir = process.cwd();

// Route to handle creating a new user
router.post("/create-user", async (req, res) => {
const newUser = req.body;

try {
await createUser(client, newUser);
res.status(200).json({ message: "User created successfully" });
} catch (error) {
console.log(error);
res.status(500).json({ message: "Internal Server Error" });
}
});

router.delete("/delete/:userId", async (req, res) => {
const userId = req.params.userId;

try {
console.log(`Deleting user with ID: ${userId}`);
// Call the deleteUserById function from data-service.js
await deleteUserById(client, userId);

res.status(200).json({ message: `User with ID ${userId} deleted successfully` });
} catch (error) {
console.error("Error deleting user:", error);
res.status(500).json({ message: "Internal Server Error" });
}
});

router.get("/time-in", (req, res) => {
res.sendFile(path.resolve(currentDir, 'views', 'time-in.html'));
});


export default router
26 changes: 26 additions & 0 deletions routes/time-in.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import express from "express";
import path from "path";
import { client } from "../models/database.js";
import { timeIn } from "../models/data-service.js";

const router = express.Router();
const currentDir = process.cwd();

router.post("/time-in", async (req, res) => {
const userId = req.body.userId;

try {
await timeIn(client, userId);
res.status(200).json({ message: "Time-in recorded successfully" });
} catch (error) {
console.log(error);
res.status(500).json({ message: "Internal Server Error" });
}
});


router.get("/time-in", (req, res) => {
res.sendFile(path.resolve(currentDir, 'views', 'time-in.html'));
});

export default router;
25 changes: 25 additions & 0 deletions routes/time-out.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import express from "express";
import path from "path";
import { client } from "../models/database.js";
import { timeOut } from "../models/data-service.js";

const router = express.Router();
const currentDir = process.cwd();

router.post("/time-out", async (req, res) => {
const userId = req.body.userId;

try {
await timeOut(client, userId);
res.status(200).json({message: "Time-out recorded successfully"})
} catch (e) {
console.error(e);
res.status(500).json({message: "Internal Server Error"})
}
});

router.get("/time-out", (req, res) => {
res.sendFile(path.resolve(currentDir, 'views', 'time-out.html'))
})

export default router;

0 comments on commit 82c8b87

Please sign in to comment.