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}`)
|
||||
}
|
||||
|
||||
|
|
|
@ -300,10 +300,8 @@ function compareQuestionObj(
|
|||
q1: Question,
|
||||
q1subjName: string,
|
||||
q2: Question,
|
||||
q2subjName: string,
|
||||
data: QuestionData
|
||||
q2subjName: string
|
||||
): any {
|
||||
assert(data !== undefined || data !== null)
|
||||
assert(q1)
|
||||
assert(typeof q1 === 'object')
|
||||
assert(q2)
|
||||
|
@ -369,8 +367,7 @@ function searchSubject(
|
|||
currentQuestion,
|
||||
subjName,
|
||||
question,
|
||||
subj.Name,
|
||||
question.data
|
||||
subj.Name
|
||||
)
|
||||
|
||||
if (percent.avg >= minMatchAmmount) {
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
export default {
|
||||
ReadFile,
|
||||
ReadJSON,
|
||||
WriteFile,
|
||||
writeFileAsync,
|
||||
AppendToFile,
|
||||
FileExists,
|
||||
CreatePath,
|
||||
WatchFile,
|
||||
ReadDir,
|
||||
CopyFile,
|
||||
GetDateString,
|
||||
formatUrl,
|
||||
ReadFile: ReadFile,
|
||||
ReadJSON: ReadJSON,
|
||||
WriteFile: WriteFile,
|
||||
writeFileAsync: writeFileAsync,
|
||||
AppendToFile: AppendToFile,
|
||||
FileExists: FileExists,
|
||||
CreatePath: CreatePath,
|
||||
WatchFile: WatchFile,
|
||||
ReadDir: ReadDir,
|
||||
CopyFile: CopyFile,
|
||||
GetDateString: GetDateString,
|
||||
formatUrl: formatUrl,
|
||||
deleteFile: deleteFile,
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue