feat:增加改nickname和avatar的接口
This commit is contained in:
@@ -28,8 +28,8 @@ module.exports = {
|
||||
},
|
||||
async changePhone (req, res) {
|
||||
const { userId } = res.locals.user;
|
||||
const { newPhone, code } = req.body;
|
||||
if (!newPhone || !code) return res.json({
|
||||
const { phone, code } = req.body;
|
||||
if (!phone || !code) return res.json({
|
||||
code: 1,
|
||||
error: 'Missing required param'
|
||||
});
|
||||
@@ -39,7 +39,7 @@ module.exports = {
|
||||
error: 'Incorrect Code'
|
||||
});
|
||||
return User.findByIdAndUpdate(userId, {
|
||||
phone: newPhone
|
||||
phone
|
||||
}).then(data => {
|
||||
res.json({
|
||||
code: 0,
|
||||
@@ -65,5 +65,25 @@ module.exports = {
|
||||
error: JSON.stringify(err)
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
async changeNickname (req, res) {
|
||||
const { userId } = res.locals.user;
|
||||
const { nickname, avatar } = req.body;
|
||||
if (!nickname && !avatar) return res.json({
|
||||
code: 1,
|
||||
error: 'Missing required param'
|
||||
});
|
||||
const update = {};
|
||||
if (nickname) update.nickname = nickname;
|
||||
if (avatar) update.avatar = avatar;
|
||||
return User.findByIdAndUpdate(userId, update).then(data => {
|
||||
res.json({
|
||||
code: 0,
|
||||
data
|
||||
});
|
||||
}).catch(err => res.json({
|
||||
code: 500,
|
||||
error: JSON.stringify(err)
|
||||
}));
|
||||
},
|
||||
};
|
||||
@@ -16,6 +16,11 @@ const services = [
|
||||
method: 'POST',
|
||||
controller: controller.changePhone
|
||||
},
|
||||
{
|
||||
url: '/chnickname',
|
||||
method: 'GET',
|
||||
controller: controller.changeNickname
|
||||
},
|
||||
{
|
||||
url: '/group',
|
||||
method: 'GET',
|
||||
|
||||
Reference in New Issue
Block a user