Checking if possible answer exist, before saving it

This commit is contained in:
mrfry 2021-03-30 11:19:00 +02:00
parent f5e157b147
commit 258ccec663
3 changed files with 37 additions and 18 deletions

View file

@ -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}`)
}