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

View File

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