mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Changed test user ID, added variable for storing questions while processing them, simplifyquestion checking for keys before using them
This commit is contained in:
parent
6f142e0733
commit
cb54f58cc6
4 changed files with 26 additions and 14 deletions
|
@ -29,7 +29,7 @@ module.exports = function(options) {
|
|||
if (process.env.NS_NOUSER) {
|
||||
req.session = {
|
||||
user: {
|
||||
id: 21323,
|
||||
id: 19,
|
||||
},
|
||||
sessionID: sessionID || 111111111111111111,
|
||||
isException: false,
|
||||
|
|
|
@ -64,6 +64,7 @@ function ProcessIncomingRequest(recievedData, qdb, infos, dryRun, user) {
|
|||
try {
|
||||
// recievedData: { version: "", id: "", subj: "" quiz: {} }
|
||||
let data = recievedData
|
||||
const recievedQuestions = []
|
||||
// FIXME: if is for backwards compatibility, remove this sometime in the future
|
||||
if (typeof data !== 'object') {
|
||||
data = JSON.parse(recievedData)
|
||||
|
@ -87,6 +88,7 @@ function ProcessIncomingRequest(recievedData, qdb, infos, dryRun, user) {
|
|||
3
|
||||
)
|
||||
logger.DebugLog(currentQuestion, 'actions', 3)
|
||||
recievedQuestions.push(currentQuestion)
|
||||
questionSearchPromises.push(searchData(qdb, currentQuestion, data.subj))
|
||||
})
|
||||
|
||||
|
@ -95,7 +97,7 @@ function ProcessIncomingRequest(recievedData, qdb, infos, dryRun, user) {
|
|||
const allQuestions = [] // all new questions here that do not have result
|
||||
results.forEach((result, i) => {
|
||||
if (result.length === 0) {
|
||||
allQuestions.push(data.quiz[i])
|
||||
allQuestions.push(recievedQuestions[i])
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -170,7 +172,10 @@ function ProcessIncomingRequest(recievedData, qdb, infos, dryRun, user) {
|
|||
})
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
logger.Log('There was en error handling incoming quiz data, see stderr', logger.GetColor('redbg'))
|
||||
logger.Log(
|
||||
'There was en error handling incoming quiz data, see stderr',
|
||||
logger.GetColor('redbg')
|
||||
)
|
||||
reject(new Error('Couldnt parse JSON data'))
|
||||
}
|
||||
})
|
||||
|
|
|
@ -155,6 +155,9 @@ function simplifyAnswer(value) {
|
|||
}
|
||||
|
||||
function simplifyQuestion(question) {
|
||||
if (!question) {
|
||||
return
|
||||
}
|
||||
if (typeof question === 'string') {
|
||||
return simplifyQA(question, [
|
||||
removeSpecialChars,
|
||||
|
@ -162,16 +165,20 @@ function simplifyQuestion(question) {
|
|||
removeAnswerLetters,
|
||||
])
|
||||
} else {
|
||||
if (question.Q) {
|
||||
question.Q = simplifyQA(question.Q, [
|
||||
removeSpecialChars,
|
||||
removeUnnecesarySpaces,
|
||||
removeAnswerLetters,
|
||||
])
|
||||
}
|
||||
if (question.A) {
|
||||
question.A = simplifyQA(question.A, [
|
||||
removeSpecialChars,
|
||||
removeUnnecesarySpaces,
|
||||
removeAnswerLetters,
|
||||
])
|
||||
}
|
||||
return question
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 760dfb0c4ec005dbd496d772c7a5278cfa5071bc
|
||||
Subproject commit 3940800ace16cdf594a03f8bd0077097a4ecb5c7
|
Loading…
Add table
Add a link
Reference in a new issue