Skip to content

Commit

Permalink
修复前端用户注册时发送重复openid导致报错问题
Browse files Browse the repository at this point in the history
  • Loading branch information
gricn committed May 6, 2020
1 parent 4c3f071 commit e60fd9d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion node/routes/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ const db = require('../db')
register.post('/', async (req, res) => {
try {
const reqBody = req.body
await db.query('insert into userinfo(openid, gender,age,province_id)\
const numQuery = await db.query('select count(openid) from userinfo where openid = $1',[reqBody.openid])
const openidnum = numQuery.rows[0].count

if(openidnum == 0){
await db.query('insert into userinfo(openid, gender,age,province_id)\
values ($1,$2,$3,$4)',[reqBody.openid, reqBody.gender, reqBody.age, reqBody.location])
}
res.send('receive register message successfully.')

} catch (e) {
console.log(e)
}
Expand Down

0 comments on commit e60fd9d

Please sign in to comment.