forked from kahu-2019/task-o
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.js
96 lines (79 loc) · 2.01 KB
/
routes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const express = require('express')
const db = require('./db')
const router = express.Router()
router.get('/', (req, res) => {
res.redirect('/login')
})
router.get('/login', (req, res) => {
res.render('login')
})
router.post('/login', (req,res) => {
return db.getUser (req.body.email)
.then((user) => {
var id = user[0].id
res.redirect('/' + id + '/home')
})
.catch(err => {
console.log(err.message)
res.status(500).send('error')
})
})
router.get('/:id/home', (req, res)=> {
return db.getAllTasks(req.params.id)
.then((tasks) =>{
var column0 = []
var column1 = []
var column2 = []
for(let task of tasks){
switch(task.status){
case 0:
column0.push(task)
break;
case 1:
column1.push(task)
break;
case 2:
column2.push(task)
break;
}
}
var arrangedTasks = {
column0,
column1,
column2
}
res.render('home',arrangedTasks)
})
.catch(err => {
console.log(err.message)
res.status(500).send('error')
})
})
router.get('/:id/task/:task', (req,res) => {
return db.getTask(req.params.task).then((task) => {
return db.getCollabs(req.params.task).then((collabs) => {
task[0].collaborators = collabs
res.render('task', task[0])
})
})
})
router.post('/:id/edit', (req,res) => {
var id = req.params.id
return db.editTask(id,req.body)
.then(() => {
res.redirect('/'+id+'/home')
})
})
router.get('/:id/add', (req, res) => {
var id = req.params.id
res.render('add-task',{id})
})
router.post('/:id/add', (req, res) => {
var UID = req.params.id
var task = req.body
return db.addTask(UID,task)
.then((itemID) => {
res.redirect('/'+UID+'/home')
})
})
module.exports = router