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,
|
dataToString,
|
||||||
getSubjNameWithoutYear,
|
getSubjNameWithoutYear,
|
||||||
createQuestion,
|
createQuestion,
|
||||||
|
compareQuestionObj,
|
||||||
} from '../../utils/classes'
|
} from '../../utils/classes'
|
||||||
import {
|
import {
|
||||||
initWorkerPool,
|
initWorkerPool,
|
||||||
|
@ -1010,6 +1011,28 @@ function GetApp(): ModuleType {
|
||||||
}
|
}
|
||||||
|
|
||||||
const savedQuestions = utils.ReadJSON(savedSubjQuestionsFilePath)
|
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({
|
savedQuestions.push({
|
||||||
fname: fname,
|
fname: fname,
|
||||||
subj: subj,
|
subj: subj,
|
||||||
|
@ -1018,7 +1041,6 @@ function GetApp(): ModuleType {
|
||||||
date: new Date(),
|
date: new Date(),
|
||||||
})
|
})
|
||||||
utils.WriteFile(JSON.stringify(savedQuestions), savedSubjQuestionsFilePath)
|
utils.WriteFile(JSON.stringify(savedQuestions), savedSubjQuestionsFilePath)
|
||||||
|
|
||||||
utils.WriteFile(JSON.stringify(questionsToSave), `${subjPath}/${fname}`)
|
utils.WriteFile(JSON.stringify(questionsToSave), `${subjPath}/${fname}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -300,10 +300,8 @@ function compareQuestionObj(
|
||||||
q1: Question,
|
q1: Question,
|
||||||
q1subjName: string,
|
q1subjName: string,
|
||||||
q2: Question,
|
q2: Question,
|
||||||
q2subjName: string,
|
q2subjName: string
|
||||||
data: QuestionData
|
|
||||||
): any {
|
): any {
|
||||||
assert(data !== undefined || data !== null)
|
|
||||||
assert(q1)
|
assert(q1)
|
||||||
assert(typeof q1 === 'object')
|
assert(typeof q1 === 'object')
|
||||||
assert(q2)
|
assert(q2)
|
||||||
|
@ -369,8 +367,7 @@ function searchSubject(
|
||||||
currentQuestion,
|
currentQuestion,
|
||||||
subjName,
|
subjName,
|
||||||
question,
|
question,
|
||||||
subj.Name,
|
subj.Name
|
||||||
question.data
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if (percent.avg >= minMatchAmmount) {
|
if (percent.avg >= minMatchAmmount) {
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
export default {
|
export default {
|
||||||
ReadFile,
|
ReadFile: ReadFile,
|
||||||
ReadJSON,
|
ReadJSON: ReadJSON,
|
||||||
WriteFile,
|
WriteFile: WriteFile,
|
||||||
writeFileAsync,
|
writeFileAsync: writeFileAsync,
|
||||||
AppendToFile,
|
AppendToFile: AppendToFile,
|
||||||
FileExists,
|
FileExists: FileExists,
|
||||||
CreatePath,
|
CreatePath: CreatePath,
|
||||||
WatchFile,
|
WatchFile: WatchFile,
|
||||||
ReadDir,
|
ReadDir: ReadDir,
|
||||||
CopyFile,
|
CopyFile: CopyFile,
|
||||||
GetDateString,
|
GetDateString: GetDateString,
|
||||||
formatUrl,
|
formatUrl: formatUrl,
|
||||||
deleteFile: deleteFile,
|
deleteFile: deleteFile,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue