-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.js
45 lines (38 loc) · 814 Bytes
/
profile.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
const User = require('../models/auth');
const {
sendOne,
sendUpdated,
sendNotFound
} = require('../helpers/responseHelpers');
function me(req, res, next) {
try {
return sendOne(res, req.user);
} catch (err) {
next(err);
}
}
async function publicProfile(req, res, next) {
try {
const { userId } = req.params;
const user = await User.findById(userId);
if (!user) return sendNotFound(res);
return sendOne(res, user.publicProfile());
} catch (err) {
next(err);
}
}
async function updateProfile(req, res, next) {
try {
const user = await User.findById(req.user._id);
Object.assign(user, req.body);
await user.save();
return sendUpdated(res, user);
} catch (err) {
next(err);
}
}
module.exports = {
me,
updateProfile,
publicProfile
};