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 user
) )
.then((result) => { .then((result) => {
const { newDb, newQuestions } = result
if (newQuestions > 0) {
data = newDb
}
res.json({ res.json({
success: newQuestions !== -1, success: result !== -1,
newQuestions: newQuestions, newQuestions: result,
}) })
}) })
}) })

View file

@ -118,7 +118,7 @@ function ProcessIncomingRequest(recievedData, qdb, infos, dryRun, user) {
3 3
) )
logger.DebugLog(currentQuestion, 'actions', 3) logger.DebugLog(currentQuestion, 'actions', 3)
qdb = addQuestion(qdb, sName, currentQuestion) addQuestion(qdb, sName, currentQuestion)
}) })
currWrites++ currWrites++
@ -129,17 +129,6 @@ function ProcessIncomingRequest(recievedData, qdb, infos, dryRun, user) {
) )
if (currWrites >= writeAfter && !dryRun) { if (currWrites >= writeAfter && !dryRun) {
currWrites = 0 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) logger.DebugLog('Writing data.json', 'actions', 1)
utils.WriteFile(JSON.stringify(qdb), dataFile) utils.WriteFile(JSON.stringify(qdb), dataFile)
logger.Log('\tData file written', color) logger.Log('\tData file written', color)

View file

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