mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Checking if possible answer exist, before saving it
This commit is contained in:
parent
f5e157b147
commit
258ccec663
3 changed files with 37 additions and 18 deletions
|
@ -46,6 +46,7 @@ import {
|
|||
dataToString,
|
||||
getSubjNameWithoutYear,
|
||||
createQuestion,
|
||||
compareQuestionObj,
|
||||
} from '../../utils/classes'
|
||||
import {
|
||||
initWorkerPool,
|
||||
|
@ -1010,6 +1011,28 @@ function GetApp(): ModuleType {
|
|||
}
|
||||
|
||||
const savedQuestions = utils.ReadJSON(savedSubjQuestionsFilePath)
|
||||
|
||||
const testExists = savedQuestions.some((savedQuestion) => {
|
||||
const data = utils.ReadJSON(`${subjPath}/${savedQuestion.fname}`)
|
||||
|
||||
return data.questions.some((dQuestion) => {
|
||||
return questions.some((question) => {
|
||||
const percent = compareQuestionObj(
|
||||
createQuestion(question),
|
||||
'',
|
||||
createQuestion(dQuestion),
|
||||
''
|
||||
)
|
||||
|
||||
return percent.avg === 100
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
if (testExists) {
|
||||
return
|
||||
}
|
||||
|
||||
savedQuestions.push({
|
||||
fname: fname,
|
||||
subj: subj,
|
||||
|
@ -1018,7 +1041,6 @@ function GetApp(): ModuleType {
|
|||
date: new Date(),
|
||||
})
|
||||
utils.WriteFile(JSON.stringify(savedQuestions), savedSubjQuestionsFilePath)
|
||||
|
||||
utils.WriteFile(JSON.stringify(questionsToSave), `${subjPath}/${fname}`)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue