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

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

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