Saving data fix round 2

This commit is contained in:
mrfry 2020-10-07 14:35:36 +02:00
parent 43734fb8f7
commit 1cf16dbafd
3 changed files with 8 additions and 30 deletions

View file

@ -728,13 +728,9 @@ function GetApp() {
user
)
.then((result) => {
const { newDb, newQuestions } = result
if (newQuestions > 0) {
data = newDb
}
res.json({
success: newQuestions !== -1,
newQuestions: newQuestions,
success: result !== -1,
newQuestions: result,
})
})
})

View file

@ -118,7 +118,7 @@ function ProcessIncomingRequest(recievedData, qdb, infos, dryRun, user) {
3
)
logger.DebugLog(currentQuestion, 'actions', 3)
qdb = addQuestion(qdb, sName, currentQuestion)
addQuestion(qdb, sName, currentQuestion)
})
currWrites++
@ -129,17 +129,6 @@ function ProcessIncomingRequest(recievedData, qdb, infos, dryRun, user) {
)
if (currWrites >= writeAfter && !dryRun) {
currWrites = 0
try {
qdb.version = infos.version
qdb.motd = infos.motd
logger.DebugLog(
'version and motd set for data.json',
'actions',
3
)
} catch (err) {
logger.Log('MOTD/Version writing/reading error!')
}
logger.DebugLog('Writing data.json', 'actions', 1)
utils.WriteFile(JSON.stringify(qdb), dataFile)
logger.Log('\tData file written', color)

View file

@ -327,7 +327,6 @@ function addQuestion(data, subj, question) {
assert(subj)
assert(question)
assert(typeof question === 'object')
let result = []
var i = 0
while (
@ -341,20 +340,14 @@ function addQuestion(data, subj, question) {
if (i < data.length) {
debugLog('Adding new question to existing subject', 'qdb add', 1)
result = [...data]
result[i].Questions = [...data[i].Questions, question]
data[i].Questions.push(question)
} else {
debugLog('Creating new subject for question', 'qdb add', 1)
result = [
...data,
{
Name: subj,
Questions: [question],
},
]
data.push({
Name: subj,
Questions: [question],
})
}
return result
}
function searchData(data, question, subjName, questionData) {