-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Henrique Sagara
authored and
Henrique Sagara
committed
Feb 17, 2024
1 parent
3d1e03b
commit 82c8b87
Showing
4 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |