-
Notifications
You must be signed in to change notification settings - Fork 2
/
snippets.js
51 lines (51 loc) · 1.47 KB
/
snippets.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
const getRouteFn = (route, schema) => {
router.get(`/${route}`, (req, res) => {
schema
.find({})
.sort('-date')
.exec((err, users) => {
if (err)
throw err;
res.json(`admin/${route}`, {users: users})
})
})
}
const getUserFn = (route, Schema) => {
router.get(`/${route}/:id`, (req, res, next) => {
Schema.find({
_id: req.params.id
}, (err, user) => {
if (err) {
throw err
}
// console.log(service)
res.json(`admin/${route}`, {user: user})
})
})
}
const activateUser = (route, Schema) => {
router.get(`/${route}/activate/:id`, (req, res, next) => {
Schema.findByIdAndUpdate({
_id: req.params.id
}, {activated: true}).then((user) => {
Schema
.find({_id: req.params.id})
.then((user) => {
res.json(`admin/${route}`, {user: user})
})
})
})
}
const deactivateUser = (route, Schema) => {
router.get(`/${route}/deactivate/:id`, (req, res, next) => {
Schema.findByIdAndUpdate({
_id: req.params.id
}, {activated: false}).then((user) => {
Schema
.find({_id: req.params.id})
.then((user) => {
res.json(`admin/${route}`, {user: user})
})
})
})
}