feat(VocabService, VocabCourseView): enhance SRS item retrieval and UI integration
All checks were successful
Deploy to production / deploy (push) Successful in 1m52s

- Updated VocabService to calculate total due count for spaced repetition system (SRS) items, improving data handling for user queries.
- Modified VocabCourseView to incorporate total due count in the UI, ensuring accurate display of SRS item statistics.
- Enhanced error handling and data validation for SRS due items, improving overall reliability and user experience.
This commit is contained in:
Torsten Schulz (local)
2026-04-17 16:53:56 +02:00
parent 7732498875
commit d2eebf1f94
2 changed files with 17 additions and 7 deletions

View File

@@ -1801,14 +1801,16 @@ export default class VocabService {
const limit = this._clampInteger(query?.limit, { min: 1, max: 100, fallback: 30 });
const now = new Date();
const dueWhere = {
userId: user.id,
courseId: Number(course.id),
nextDueAt: {
[Op.lte]: now
}
};
const totalDueCount = await VocabSrsItem.count({ where: dueWhere });
const rows = await VocabSrsItem.findAll({
where: {
userId: user.id,
courseId: Number(course.id),
nextDueAt: {
[Op.lte]: now
}
},
where: dueWhere,
order: [
['nextDueAt', 'ASC'],
['wrongCount', 'DESC'],
@@ -1821,6 +1823,8 @@ export default class VocabService {
courseId: course.id,
dueAt: now.toISOString(),
count: rows.length,
totalDueCount,
limit,
items: rows.map((item) => ({
itemKey: item.itemKey,
courseId: item.courseId,

View File

@@ -341,6 +341,7 @@ export default {
progress: [],
chapters: [],
srsDueItems: [],
srsDueTotal: 0,
srsLoading: false,
showAddLessonDialog: false,
assistantSettings: null,
@@ -384,6 +385,9 @@ export default {
return this.currentLesson?.pedagogy?.blockNumber || null;
},
srsDueCount() {
if (Number.isFinite(Number(this.srsDueTotal)) && Number(this.srsDueTotal) > 0) {
return Number(this.srsDueTotal);
}
return Array.isArray(this.srsDueItems) ? this.srsDueItems.length : 0;
},
dueReviewLessons() {
@@ -553,9 +557,11 @@ export default {
params: { limit: 40 }
});
this.srsDueItems = Array.isArray(data?.items) ? data.items : [];
this.srsDueTotal = Number.isFinite(Number(data?.totalDueCount)) ? Number(data.totalDueCount) : this.srsDueItems.length;
} catch (e) {
console.warn('Konnte SRS-Fälligkeiten nicht laden:', e);
this.srsDueItems = [];
this.srsDueTotal = 0;
} finally {
this.srsLoading = false;
}