mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Saving data fix round 2
This commit is contained in:
parent
43734fb8f7
commit
1cf16dbafd
3 changed files with 8 additions and 30 deletions
|
@ -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,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue