Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syihab Muchsin #37

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions server/controllers/task-controller.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const { Task } = require('../models')
const { Task, User, Department } = require('../models')


class TaskController{
static async getAll(req,res){
muchsin28 marked this conversation as resolved.
Show resolved Hide resolved
try{
let tasks = await Task.findAll({
where: {
UserId: req.loggedIn.id
include: {
model:User,
include: Department
},
// include: ,
order: [['due', 'ASC']]
order: [['createdAt', 'DESC']]
});
console.log(tasks)
res.status(200).json(tasks)
Expand Down
8 changes: 4 additions & 4 deletions server/middlewares/authorization.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
//Authorization
const { Todo } = require('../models')
const { Task } = require('../models')
const Authorization = async (req, res, next) => {
try {
const todo = await Todo.findOne({
const task = await Task.findOne({
where: { id: +req.params.id }
})
if(!todo){
if( task){
throw {
status: 404,
message: 'Item not found'
}
}else if (todo.UserId != req.loggedIn.id) {
}else if (task.UserId != req.loggedIn.id) {
throw {
status: 401,
message: 'You are not allowed to do this action'
Expand Down
9 changes: 7 additions & 2 deletions server/routes/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@

const router = require('express').Router()
const { UserController, TaskController } = require('../controllers')
const {Authentication, Authorization} = require('../middlewares')
const { Authentication, Authorization } = require('../middlewares')


router.post('/register', UserController.register)
router.post('/login', UserController.login)
// router.post('/google-login', UserController.googleLogin)
// router.post('/', UserController.githubLogin)

//Authentication Required
router.use(Authentication)
router.get('/', TaskController.getAll)
router.get('/tasks', TaskController.getAll)
router.post('/add', TaskController.create)
muchsin28 marked this conversation as resolved.
Show resolved Hide resolved

//Authorization Required
router.use('/:id',Authorization)
// router.pacth('/:id', TaskController.update)
// router.put('/:id', TaskController.edit)
// router.delete('/:id', TaskController.delete)


module.exports = router
Expand Down