Skip to content

Commit

Permalink
format fix
Browse files Browse the repository at this point in the history
  • Loading branch information
up2code3 committed Nov 26, 2024
1 parent 6ad2632 commit aff0cec
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 20 deletions.
10 changes: 3 additions & 7 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@ const connectDB = require("../config/db");
const medicationRoutes = require("./routes/medicationRoutes.js");
require("dotenv").config();


const mainRouter = require('./routes/mainRouter.js');
const testRoutes = require('./routes/testRoutes');
const authRoutes = require('./routes/authRoutes');
const authRoutes = require("./routes/authRoutes");
const app = express();
const cors = require("cors");
const favicon = require("express-favicon");
const logger = require("morgan");


const mainRouter = require("./routes/mainRouter.js");
const testRoutes = require("./routes/testRoutes");
const errorHandler = require("./middleware/errorHandler.js");
Expand All @@ -29,8 +25,8 @@ app.use(express.static("public"));
app.use(favicon(__dirname + "/public/favicon.ico"));

// routes
app.use('/api/v1', mainRouter);
app.use('/api/v1/test', testRoutes);
app.use("/api/v1", mainRouter);
app.use("/api/v1/test", testRoutes);
app.use("/api/v1/auth", authRoutes);
app.use("/api/v1", mainRouter);
app.use("/api/v1/test", testRoutes);
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/authController.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const User = require("../models/UserModel");
const bcrypt = require("bcryptjs");

const jwt = require("jsonwebtoken");

// Controller for Signup
Expand Down Expand Up @@ -51,7 +51,7 @@ const login = async (req, res) => {
const token = jwt.sign(
{ id: user._id, role: user.role },
process.env.JWT_SECRET,
{ expiresIn: "1h" }
{ expiresIn: "1h" },
);

res.status(200).json({
Expand Down
1 change: 0 additions & 1 deletion src/controllers/mainController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

const mainController = {};

mainController.get = (req, res) => {
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/authMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const authenticate = (req, res, next) => {

// Attach the user data (from token) to the request object
req.user = decoded;
next();
next();
} catch (err) {
return res.status(400).json({
success: false,
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/roleMiddleware.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const roleMiddleware = (requiredRoles) => {
return (req, res, next) => {
const userRole = req.user?.role;
const userRole = req.user?.role;

if (!requiredRoles.includes(userRole)) {
return res.status(403).json({
Expand Down
2 changes: 1 addition & 1 deletion src/models/UserModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const userSchema = new mongoose.Schema(
},
{
timestamps: true,
}
},
);

// Hash password before saving the user
Expand Down
6 changes: 3 additions & 3 deletions src/routes/authRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ router.get(
roleMiddleware(["admin"]),
(req, res) => {
res.status(200).json({ message: "Welcome, Admin!" });
}
},
);

router.get(
Expand All @@ -23,7 +23,7 @@ router.get(
roleMiddleware(["admin", "inventoryManager"]), // Admins and inventory managers can access
(req, res) => {
res.status(200).json({ message: "Welcome, Inventory Manager!" });
}
},
);

router.get(
Expand All @@ -32,7 +32,7 @@ router.get(
roleMiddleware(["admin", "inventoryManager", "clerk"]), // Allow clerk access
(req, res) => {
res.status(200).json({ message: "Welcome, Clerk!" });
}
},
);

module.exports = router;
6 changes: 2 additions & 4 deletions src/routes/testRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ router.post("/test-create-user", async (req, res, next) => {
router.get("/test-get-user", async (req, res, next) => {
try {
const user = await User.findOne({ email: req.query.email }).select(
"+password"
"+password",
);
if (!user) {
return res
Expand Down Expand Up @@ -184,9 +184,7 @@ router.post("/test-reset-password", async (req, res, next) => {

const isMatch = await user.comparePassword(currentPassword);
if (!isMatch) {
return res
.status(401)
.json({ message: "Current password is incorrect" });
return res.status(401).json({ message: "Current password is incorrect" });
}

user.password = newPassword;
Expand Down

0 comments on commit aff0cec

Please sign in to comment.