stricter subj name checking on question add, should log test fix

This commit is contained in:
mrfry 2023-03-07 19:43:55 +01:00
parent 537f4c413e
commit d962abfbc2
5 changed files with 144 additions and 51 deletions

View file

@ -215,7 +215,13 @@ function processIncomingRequestUsingDb(
const subjName = getSubjNameWithoutYear(
recievedData.subj
)
if (allQuestions.length > 0) {
if (!subjName) {
logger.Log(
`Subject name is empty! Tried to create name from: ${recievedData.subj}, but got empty string!`,
logger.GetColor('redbg')
)
}
if (allQuestions.length > 0 && subjName) {
addQuestionsToDb(allQuestions, subjName, qdb)
currWrites++

View file

@ -499,16 +499,17 @@ function addQuestion(
logger.DebugLog(question, 'qdb add', 3)
const i = data.findIndex((subject) => {
return subj
.toLowerCase()
.includes(getSubjNameWithoutYear(subject.Name).toLowerCase())
return (
subj.toLowerCase() ===
getSubjNameWithoutYear(subject.Name).toLowerCase()
)
})
if (i !== -1) {
logger.DebugLog('Adding new question to existing subject', 'qdb add', 1)
data[i].Questions.push(question)
} else {
logger.DebugLog('Creating new subject for question', 'qdb add', 1)
logger.Log(`Creating new subject: ${subj}`)
data.push({
Name: subj,
Questions: [question],