-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from mdsreq-fga-unb/feature/frontRefactor
Feature/front refactor
- Loading branch information
Showing
38 changed files
with
1,021 additions
and
866 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
MONGODB_URL= | ||
SOFTWARE_URL= | ||
DB_NAME= | ||
SECRET_JWT= |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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,36 @@ | ||
import dotenv from 'dotenv'; | ||
import jwt from 'jsonwebtoken'; | ||
import userService from '../services/user.service.js'; | ||
|
||
dotenv.config(); | ||
|
||
export const authMiddleware = (req, res, next) => { | ||
try { | ||
const { authorization } = req.headers; | ||
console.log(authorization); | ||
|
||
if (!authorization) return res.status(401).send({message: 'User Unauthorized'}); | ||
|
||
const parts = authorization.split(" "); | ||
|
||
if (parts.length !== 2) return res.status(401).send({message: 'User Unauthorized'}); | ||
|
||
const [schema, token] = parts; | ||
|
||
if (schema !== "Bearer") return res.status(401).send({message: 'User Unauthorized'}); | ||
|
||
jwt.verify(token, process.env.SECRET_JWT, async (error, decoded) => { | ||
if(error) return res.status(401).send({message: 'Token Invalid'}); | ||
|
||
const user = await userService.findOneService({ _id: decoded._id}); | ||
|
||
if (!user || !user.id) return res.status(401).send({message: "Invalid User!"}); | ||
|
||
req.userID = decoded._id; | ||
|
||
return next(); | ||
}); | ||
} catch(err) { | ||
return res.status(500).send({ message: err.message }); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,12 +1,13 @@ | ||
import express from 'express'; | ||
import unitController from '../controllers/unit.controller.js'; | ||
import { authMiddleware } from '../middleware/auth.middleware.js'; | ||
|
||
const unitRouter = express.Router() | ||
|
||
unitRouter.get('/findAllUnit', unitController.findAllUnit); | ||
unitRouter.get('/findByCode/:code', unitController.findByCodeUnit); | ||
unitRouter.post('/createUnit',unitController.createUnit); | ||
unitRouter.patch('/updateUnit/:id', unitController.updateUnit); | ||
unitRouter.delete('/deleteUnit/:id',unitController.deleteUnit); | ||
unitRouter.get('/findAllUnit', authMiddleware, unitController.findAllUnit); | ||
unitRouter.get('/findByCode/:code', authMiddleware, unitController.findByCodeUnit); | ||
unitRouter.post('/createUnit', authMiddleware,unitController.createUnit); | ||
unitRouter.patch('/updateUnit/:id', authMiddleware, unitController.updateUnit); | ||
unitRouter.delete('/deleteUnit/:id', authMiddleware, unitController.deleteUnit); | ||
|
||
export default unitRouter; |
File renamed without changes.
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 |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import express from 'express'; | ||
import { authMiddleware } from '../middleware/auth.middleware.js'; | ||
|
||
const userRouter = express.Router(); | ||
|
||
import userController from '../controllers/user.controller.js'; | ||
|
||
userRouter.get('/findAllUser', userController.findAllUser); | ||
userRouter.get('/findAllUser', authMiddleware, userController.findAllUser); | ||
userRouter.post('/createUser', userController.createUser); | ||
userRouter.post('/loginUser', userController.loginUser); | ||
userRouter.patch('/updateUser/:id', userController.updateUser); | ||
userRouter.delete("/deleteUser/:id", userController.deleteUser); | ||
userRouter.patch('/updateUser/:id', authMiddleware, userController.updateUser); | ||
userRouter.delete("/deleteUser/:id", authMiddleware, userController.deleteUser); | ||
|
||
export default userRouter; |
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 |
---|---|---|
@@ -1,16 +1,18 @@ | ||
import User from '../models/User.js'; | ||
|
||
import jwt from 'jsonwebtoken'; | ||
|
||
const findAllService = () => User.find(); | ||
const createService = (body) => User.create(body); | ||
const findOneService = (body) => User.findOne(body); | ||
const updateService = (params, body) => User.findOneAndUpdate(params, body, {new: true}); | ||
const deleteService = (params) => User.findOneAndDelete(params) | ||
const generateToken = (id) => jwt.sign({_id: id}, process.env.SECRET_JWT, {expiresIn: 86400}); | ||
|
||
export default { | ||
createService, | ||
findOneService, | ||
findAllService, | ||
updateService, | ||
deleteService, | ||
generateToken, | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
Oops, something went wrong.