Changed test user ID, added variable for storing questions while processing them, simplifyquestion checking for keys before using them

This commit is contained in:
mrfry 2020-10-21 16:26:46 +02:00
parent 6f142e0733
commit cb54f58cc6
4 changed files with 26 additions and 14 deletions

View file

@ -29,7 +29,7 @@ module.exports = function(options) {
if (process.env.NS_NOUSER) { if (process.env.NS_NOUSER) {
req.session = { req.session = {
user: { user: {
id: 21323, id: 19,
}, },
sessionID: sessionID || 111111111111111111, sessionID: sessionID || 111111111111111111,
isException: false, isException: false,

View file

@ -64,6 +64,7 @@ function ProcessIncomingRequest(recievedData, qdb, infos, dryRun, user) {
try { try {
// recievedData: { version: "", id: "", subj: "" quiz: {} } // recievedData: { version: "", id: "", subj: "" quiz: {} }
let data = recievedData let data = recievedData
const recievedQuestions = []
// FIXME: if is for backwards compatibility, remove this sometime in the future // FIXME: if is for backwards compatibility, remove this sometime in the future
if (typeof data !== 'object') { if (typeof data !== 'object') {
data = JSON.parse(recievedData) data = JSON.parse(recievedData)
@ -87,6 +88,7 @@ function ProcessIncomingRequest(recievedData, qdb, infos, dryRun, user) {
3 3
) )
logger.DebugLog(currentQuestion, 'actions', 3) logger.DebugLog(currentQuestion, 'actions', 3)
recievedQuestions.push(currentQuestion)
questionSearchPromises.push(searchData(qdb, currentQuestion, data.subj)) 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 const allQuestions = [] // all new questions here that do not have result
results.forEach((result, i) => { results.forEach((result, i) => {
if (result.length === 0) { 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) { } catch (err) {
console.error(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')) reject(new Error('Couldnt parse JSON data'))
} }
}) })

View file

@ -155,6 +155,9 @@ function simplifyAnswer(value) {
} }
function simplifyQuestion(question) { function simplifyQuestion(question) {
if (!question) {
return
}
if (typeof question === 'string') { if (typeof question === 'string') {
return simplifyQA(question, [ return simplifyQA(question, [
removeSpecialChars, removeSpecialChars,
@ -162,16 +165,20 @@ function simplifyQuestion(question) {
removeAnswerLetters, removeAnswerLetters,
]) ])
} else { } else {
if (question.Q) {
question.Q = simplifyQA(question.Q, [ question.Q = simplifyQA(question.Q, [
removeSpecialChars, removeSpecialChars,
removeUnnecesarySpaces, removeUnnecesarySpaces,
removeAnswerLetters, removeAnswerLetters,
]) ])
}
if (question.A) {
question.A = simplifyQA(question.A, [ question.A = simplifyQA(question.A, [
removeSpecialChars, removeSpecialChars,
removeUnnecesarySpaces, removeUnnecesarySpaces,
removeAnswerLetters, removeAnswerLetters,
]) ])
}
return question return question
} }
} }

@ -1 +1 @@
Subproject commit 760dfb0c4ec005dbd496d772c7a5278cfa5071bc Subproject commit 3940800ace16cdf594a03f8bd0077097a4ecb5c7