-
Notifications
You must be signed in to change notification settings - Fork 0
/
followController.js
34 lines (25 loc) · 996 Bytes
/
followController.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
const Follow = require('../models/Follow')
exports.addFollow = function (req, res) {
let follow = new Follow(req.params.username, req.visitorId)
follow.create().then(() => {
req.flash("success", `Successfully followed ${req.params.username}`)
req.session.save(() => res.redirect(`/profile/${req.params.username}`))
}).catch((errors) => {
errors.forEach(error => {
req.flash("errors", error)
})
req.session.save(() => res.redirect('/'))
})
}
exports.removeFollow = function (req, res) {
let follow = new Follow(req.params.username, req.visitorId)
follow.delete().then(() => {
req.flash("success", `Successfully Stopped Following ${req.params.username}`)
req.session.save(() => res.redirect(`/profile/${req.params.username}`))
}).catch((errors) => {
errors.forEach(error => {
req.flash("errors", error)
})
req.session.save(() => res.redirect('/'))
})
}