Add rating system for community questions
This commit is contained in:
@@ -1,12 +1,37 @@
|
||||
export class OpenEndedQuestion {
|
||||
constructor (id, question, solution, creator, created, ratings, difficulty) {
|
||||
constructor (id, question, solution, creator, created, helpful, difficulty) {
|
||||
this.id = id
|
||||
this.question = question
|
||||
this.solution = solution
|
||||
this.creator = creator
|
||||
this.created = created
|
||||
this.ratings = ratings
|
||||
this.difficulty = difficulty
|
||||
this.helpful = helpful || []
|
||||
this.difficulty = {
|
||||
easy: difficulty.leicht || [],
|
||||
medium: difficulty.mittel || [],
|
||||
hard: difficulty.schwer || []
|
||||
}
|
||||
this.updateDifficultyLevel()
|
||||
}
|
||||
|
||||
updateDifficultyLevel () {
|
||||
const easyCount = this.difficulty.easy.length
|
||||
const mediumCount = this.difficulty.medium.length
|
||||
const hardCount = this.difficulty.hard.length
|
||||
|
||||
if (hardCount > 0 && hardCount >= mediumCount && hardCount >= easyCount) this.difficultyLevel = 3
|
||||
else if (mediumCount > 0 && mediumCount >= hardCount && mediumCount >= easyCount) this.difficultyLevel = 2
|
||||
else if (easyCount > 0 && easyCount >= hardCount && easyCount >= mediumCount) this.difficultyLevel = 1
|
||||
else this.difficultyLevel = null
|
||||
}
|
||||
|
||||
getDifficultyString () {
|
||||
switch (this.difficultyLevel) {
|
||||
case 1: return 'Leicht'
|
||||
case 2: return 'Mittel'
|
||||
case 3: return 'Schwer'
|
||||
default: return 'Unbewertet'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +43,16 @@ export const OpenEndedQuestionConverter = {
|
||||
musterloesung: openEndedQuestion.solution,
|
||||
ersteller: openEndedQuestion.creator,
|
||||
erstellt: openEndedQuestion.created,
|
||||
bewertungen: openEndedQuestion.ratings,
|
||||
schwierigkeit: openEndedQuestion.difficulty
|
||||
hilfreich: openEndedQuestion.helpful,
|
||||
schwierigkeit: {
|
||||
leicht: openEndedQuestion.difficulty.easy,
|
||||
mittel: openEndedQuestion.difficulty.medium,
|
||||
schwer: openEndedQuestion.difficulty.hard
|
||||
}
|
||||
}
|
||||
},
|
||||
fromFirestore: (snapshot, options) => {
|
||||
const data = snapshot.data(options)
|
||||
return new OpenEndedQuestion(snapshot.id, data.frage, data.musterloesung, data.ersteller, data.erstellt, data.bewertungen, data.schwierigkeit)
|
||||
return new OpenEndedQuestion(snapshot.id, data.frage, data.musterloesung, data.ersteller, data.erstellt, data.hilfreich, data.schwierigkeit)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user