-
Notifications
You must be signed in to change notification settings - Fork 164
/
Copy path214754100
185 lines (124 loc) · 5.53 KB
/
214754100
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
const mysql = require('mysql');
const express =require('express');
const router = express.Router();
const db = require('../config/conn');
const mysqlConn= require('../config/conn');
//get all client
// Retrieve all artisan
router.get('/artisan/:id', function (req, res) {
let userType={userType:req.body.userType}
mysqlConn.query('SELECT * FROM user where userType= ',+ req.param.userType,userType ,function (error, results, fields) {
if (error) throw error;
return res.send({ error: false, data: results, message: 'artisan list.' });
});
});
// Retrieve client/artisan with id
router.get('/artisan/:id', function (req, res) {
let user_id = req.params.clientid;
mysqlConn.query('SELECT * FROM artisan WHERE id = ?', user_id, (error, result) => {
if (error) throw error;
response.send(result);
});
});
// Add a new user
router.post('/artisan', function (req, res) {
let post = {name:req.body.name,surname:req.body.surname,email:req.body.email,address:req.body.address,password:req.body.password,userType:req.body.userType,userId:req.body.userId};
if (!post) {
return res.status(400).send({ error:true, message: 'Please provide user' });
}
mysqlConn.query("INSERT INTO user SET ? ",[post], function (error, results, fields) {
if (error) throw error;
return res.send({ error: false, data: results, message: 'New user has been created successfully.' });
});
});
//deleting from db
// Delete user
router.delete('/artisan/:id', function (req, res) {
let user_id = {userId:res.body.userId};
if (!user_id) {
return res.status(400).send({ error: true, message: 'Please provide user_id' });
}
mysqlConn.query('DELETE FROM artisan WHERE id = ',req.param.userId ,user_id, function (error, results, fields) {
if (error) throw error;
return res.send({ error: false, data: results, message: 'User has been updated successfully.' });
});
});
// api for categories
router.get('/category', function (req, res) {
mysqlConn.query('SELECT * FROM categories', function (error, results, fields) {
if (error) throw error;
return res.send({ error: false, data: results, message: 'category list.' });
});
});
// Retrieve category by id
router.get('/category/:id', function (req, res) {
let catid={catId:req.body.catId};
mysqlConn.query('SELECT * FROM categories WHERE catId = ?',[catid] ,(error, result) => {
if (error) throw error;
res.send(result);
});
});
// Add a new category
router.post('/category', function (req, res) {
let post = {catId:req.body.catId,CatName:req.body.CatName};
if (!post) {
return res.status(400).send({ error:true, message: 'Please provide user' });
}
mysqlConn.query("INSERT INTO categories SET ? ",[post], function (error, results, fields) {
if (error) throw error;
return res.send({ error: false, data: results, message: 'New user has been created successfully.' });
});
});
//deleting from db
// Deleting category
router.delete('/category/:id', function (req, res) {
let user_id = {catId:req.body.catId};
if (!user_id) {
return res.status(400).send({ error: true, message: 'Please provide user_id' });
}
mysqlConn.query('DELETE FROM categories WHERE catId =?', [user_id], function (error, results, fields) {
if (error) throw error;
return res.send({ error: false, data: results, message: 'User has been updated successfully.' });
});
});
// api for jobposter
// get all job poster
router.get('/jobposter/:userType', function (req, res) {
let userType={userType:req.body.userType}
mysqlConn.query('SELECT * FROM user where userType =?',[userType], function (error, results, fields) {
if (error) throw error;
return res.send({ error: false, data: results, message: 'category list.' });
});
});
// Retrieve category by id
router.get('/jobposter/:id', function (req, res) {
let userId={catId:req.body.catId};
mysqlConn.query('SELECT * FROM categories WHERE userId = ?',[catid] ,(error, result) => {
if (error) throw error;
res.send(result);
});
});
// Add a new jobposter
router.post('/jobposter', function (req, res) {
let post = {name:req.body.name,surname:req.body.surname,email:req.body.email,address:req.body.address,password:req.body.password,userType:req.body.userType,userId:req.body.userId};
if (!post) {
return res.status(400).send({ error:true, message: 'Please provide user' });
}
mysqlConn.query("INSERT INTO user SET ? ",[post], function (error, results, fields) {
if (error) throw error;
return res.send({ error: false, data: results, message: 'New user has been created successfully.' });
});
});
//deleting from db
// Deleting jobposter
router.delete('/jobposter/:id', function (req, res) {
let user_id = {userId:req.body.userId};
if (!user_id) {
return res.status(400).send({ error: true, message: 'Please provide user_id' });
}
mysqlConn.query('DELETE FROM user WHERE userId=?', [user_id], function (error, results, fields) {
if (error) throw error;
return res.send({ error: false, data: results, message: 'User has been updated successfully.' });
});
});
module.exports=router;