Skip to content

Commit

Permalink
修复testdetail表openid不存在时test_times填写异常bug
Browse files Browse the repository at this point in the history
  • Loading branch information
gricn committed May 6, 2020
1 parent 315e7a1 commit 4c3f071
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions node/routes/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,33 @@ const db = require('../db')

test.post('/', async (req, res) => {
try {
console.log(req.body)
res.send("Server has received test results. Thanks for your paticipating.")
var reqBody = req.body
var openid = reqBody.openid
var testtimes = reqBody.testtimes
var question_id = ""

reqBody.index.forEach((type, i) => {
type.forEach((question, j)=>{
var tmp1 = i+1
var tmp2 = j+1
var queryResult = await db.query("select max(test_times) from testdetail \
where question_id = 't1_1' and openid= $1", [openid])

var testtimes = (queryResult == undefined) ? 1 : queryResult.rows[0].max + 1

await reqBody.index.forEach(async (type, i) => {
type.forEach(async (question, j) => {
var tmp1 = i + 1
var tmp2 = j + 1
question_id = "t" + tmp1 + "_" + tmp2
question_value = reqBody.index[i][j].sliderValue
//question.value
const { rows } = db.query(

await db.query(
'insert into testdetail(openid, test_times, question_id, question_value) \
values($1, $2, $3, $4)',
[openid, testtimes, question_id, question_value])
})
})

console.log('服务器存储testtimes成功,值为:' + testtimes)
} catch (e) {
console.log(e)
}

})

module.exports = test

0 comments on commit 4c3f071

Please sign in to comment.