修复了无法修改个人信息的bug

master
P-Jhao 3 days ago
parent bf6a9bff1f
commit ea5a1152fd

@ -18,3 +18,11 @@ module.exports.updateUserDao = async function (loginInfo) {
}
})
}
module.exports.getUserInfoDao = async function (loginId) {
return await userModel.findOne({
where: {
loginId,
}
})
}

@ -2,7 +2,8 @@ var express = require('express');
var router = express.Router();
const {
loginService,
updateUserInfoService
updateUserInfoService,
getUserInfoService
} = require("../services/userService")
const {
formatResponse,
@ -29,27 +30,16 @@ router.get("/whoami", async function (req, res, next) {
//获取token,然后进行解析
const {
loginId,
sex,
brithday,
region,
number
} = analysisToken(req.get("authorization"))
res.send(formatResponse(0, "", {
loginId,
sex,
brithday,
region,
number
}))
const {
loginPwd,
...data
} = await getUserInfoService(loginId)
res.send(formatResponse(0, "", data))
})
router.put("/", async function (req, res, next) {
const {
token,
data
} = await updateUserInfoService(req.body)
res.setHeader("authentication", token)
const data = await updateUserInfoService(req.body)
res.send(formatResponse(0, "", data))
})

@ -1,7 +1,8 @@
const md5 = require('md5');
const {
loginDao,
updateUserDao
updateUserDao,
getUserInfoDao
} = require("../dao/userDao")
const jwt = require("jsonwebtoken");
const {
@ -31,16 +32,13 @@ module.exports.loginService = async function (loginInfo) {
}
module.exports.updateUserInfoService = async function (userInfo) {
const data = userInfo
data.loginPwd = md5(data.loginPwd)
await updateUserDao(data)
const {
loginPwd,
...result
} = userInfo
//重新赋值token
return {
token: getJwtToken(result),
data: result
await updateUserDao(userInfo)
const data = await getUserInfoDao(userInfo.loginId)
return data.dataValues
}
module.exports.getUserInfoService = async function (loginId) {
const data = await getUserInfoDao(loginId)
return data.dataValues
}
Loading…
Cancel
Save