-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject.js
More file actions
141 lines (119 loc) · 4.56 KB
/
project.js
File metadata and controls
141 lines (119 loc) · 4.56 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
'''Employee Management System Task'''
import express from 'express'
import bodyParser from 'body-parser'
import dotenv from 'dotenv'
import Sequelize from 'sequelize'
import bcrypt from 'bcrypt'
const app = express()
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
const sequelize = new Sequelize('management', 'root', '', {
host: 'localhost',
dialect: 'mysql'
});
sequelize
.authenticate()
.then(() => {
console.log('Connection has been established successfully.');
})
.catch(err => {
console.error('Unable to connect to the database:', err);
});
dotenv.config()
app.post('/member/signin',async (req,res)=>{
let result = await sequelize.query(`Select password from member where email='${req.body.name}' OR mobile='${req.body.name}'`)
if(result[0].length==0){
res.send("name is invalid!")
}
else{
let hash = result[0][0]['password']
bcrypt.compare(req.body.password, hash, async function(err, response) {
res.json(response)
});
}
})
app.get('/project',async (req,res)=>{
let result = await sequelize.query("Select * from project")
res.json(result[0])
})
app.post('/project',async (req,res)=>{
let result = await sequelize.query(`Insert into project values(null,'${req.body.name}','${req.body.startdate}','${req.body.daysalloted}')`)
res.json(result)
})
app.get('/member',async (req,res)=>{
let result = await sequelize.query("Select * from member")
res.json(result[0])
})
app.post('/member',async (req,res)=>{
console.log(process.env.SALTROUNDS)
bcrypt.hash(req.body.password, parseInt(process.env.SALTROUNDS), async function(err, hash) {
if(err){
res.send(err)
console.log(err)
return
}
let result = await sequelize.query(`Insert into member values(null,'${req.body.name}','${req.body.mobile}','${req.body.email}','${hash}')`)
res.json(result)
});
})
app.get('/project_member',async (req,res)=>{
let query = `Select project.name as 'project_name', member.name as 'member_name' FROM project,member, member_project
where member_project.p_id = project.p_id AND member_project.m_id = member.m_id`
let response = await sequelize.query(query)
res.json(response)
})
app.get('/alloted_time',async (req,res)=>{
let result = await sequelize.query("Select * from member_project")
res.json(result[0])
})
app.get('/task',async (req,res)=>{
let result = await sequelize.query("Select * from task")
res.json(result)
})
app.post('/task',async (req,res)=>{
let result = await sequelize.query(`Insert into task values(null,'${req.body.name}','${req.body.allottedto}','${req.body.allottedby}','${req.body.p_id}','${req.body.type}','${req.body.points}')`)
res.json(result)
})
app.get('/subtask',async (req,res)=>{
let result = await sequelize.query("Select * from subtask")
res.json(result[0])
})
app.post('/subtask',async (req,res)=>{
let result = await sequelize.query(`Insert into subtask values(null,'${req.body.name}','${req.body.description}','${req.body.allottedto}','${req.body.allottedby}','${req.body.points}','${req.body.t_id}')`)
res.json(result)
})
app.get('/gettask',async (req,res)=>{
let query = `Select * FROM task,subtask
where subtask.t_id=task.t_id`
let response = await sequelize.query(query)
res.json(response)
})
app.get('/allotted_by',async (req,res)=>{
let query = `Select project.name as 'project_name',member.name as 'member_allotted_by' FROM project,task,member
WHERE task.p_id=project.p_id AND task.allottedby=member.m_id `
let response = await sequelize.query(query)
res.json(response)
})
app.get('/allotted_to',async (req,res)=>{
let query = `Select project.name as 'project_name',member.name as 'member_allotted_to' FROM project,task,member
WHERE task.p_id=project.p_id AND task.allottedto=member.m_id `
let response = await sequelize.query(query)
res.json(response)
})
app.get('/sprint',async (req,res)=>{
let result = await sequelize.query("Select * from sprint")
res.json(result[0])
})
app.post('/sprint',async (req,res)=>{
let result = await sequelize.query(`Insert into sprint values(null,'${req.body.name}','${req.body.days}','${req.body.startdate}','${req.body.enddate}')`)
res.json(result)
})
app.get('/sprinttask',async (req,res)=>{
let query = `Select * FROM task,sprint,task_sprint
WHERE task_sprint.sprint_id=sprint.sprint_id AND task_sprint.t_id=task.t_id`
let response = await sequelize.query(query)
res.json(response)
})
app.listen(process.env.PORT,()=>{
console.log("Server Started")
})