fix
This commit is contained in:
100
src/lib/db.js
100
src/lib/db.js
@@ -96,28 +96,14 @@ export async function deleteContent(topicId) {
|
||||
} catch { /* no record, nothing to do */ }
|
||||
}
|
||||
|
||||
// ── Quiz Banks ───────────────────────────────────────────────────────────────
|
||||
// ── Quiz Banks (DEPRECATED — collection dropped) ────────────────────────────
|
||||
|
||||
function normalizeQuizQuestion(q) {
|
||||
if (!q || typeof q !== 'object') return q;
|
||||
return q.difficulty ? q : { ...q, difficulty: 'medium' };
|
||||
}
|
||||
|
||||
export async function getQuizBank(topicId) {
|
||||
try {
|
||||
const r = await pb.collection('quiz_banks').getFirstListItem(`topic_id="${topicId}"`);
|
||||
return (r.questions || []).map(normalizeQuizQuestion);
|
||||
} catch { return []; }
|
||||
}
|
||||
|
||||
export function setQuizBank(topicId, questions) {
|
||||
return pbUpsert('quiz_banks', `topic_id="${topicId}"`, { questions }, { topic_id: topicId, questions });
|
||||
}
|
||||
|
||||
export async function deleteQuestionFromBank(topicId, questionId) {
|
||||
const questions = await getQuizBank(topicId);
|
||||
return setQuizBank(topicId, questions.filter(q => q.id !== questionId));
|
||||
}
|
||||
/** @deprecated quiz_banks collection has been dropped. */
|
||||
export async function getQuizBank() { return []; }
|
||||
/** @deprecated quiz_banks collection has been dropped. */
|
||||
export async function setQuizBank() { return null; }
|
||||
/** @deprecated quiz_banks collection has been dropped. */
|
||||
export async function deleteQuestionFromBank() { return null; }
|
||||
|
||||
// ── Sources ──────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -173,61 +159,26 @@ export async function deleteTeamMember(id) {
|
||||
return pb.collection('team_members').delete(id);
|
||||
}
|
||||
|
||||
// ── Quiz Results ─────────────────────────────────────────────────────────────
|
||||
// ── Quiz Results (DEPRECATED — collection dropped) ──────────────────────────
|
||||
|
||||
export async function getQuizResult(userId, weekNumber) {
|
||||
try {
|
||||
return await pb.collection('quiz_results').getFirstListItem(
|
||||
`user_id="${userId}" && week_number=${weekNumber}`
|
||||
);
|
||||
} catch { return null; }
|
||||
}
|
||||
/** @deprecated quiz_results collection has been dropped. */
|
||||
export async function getQuizResult() { return null; }
|
||||
/** @deprecated quiz_results collection has been dropped. */
|
||||
export async function saveQuizResult() { return null; }
|
||||
|
||||
export async function saveQuizResult(userId, weekNumber, result) {
|
||||
return pb.collection('quiz_results').create({
|
||||
user_id: userId,
|
||||
week_number: weekNumber,
|
||||
score: result.score,
|
||||
total: result.total,
|
||||
percentage: result.percentage,
|
||||
time_used: result.timeUsed,
|
||||
completed_at: result.completedAt,
|
||||
breakdown: result.breakdown,
|
||||
points_earned: result.pointsEarned,
|
||||
});
|
||||
}
|
||||
// ── Quiz Cache (DEPRECATED — collection dropped) ────────────────────────────
|
||||
|
||||
// ── Quiz Cache ────────────────────────────────────────────────────────────────
|
||||
/** @deprecated quiz_cache collection has been dropped. */
|
||||
export async function getCachedQuiz() { return null; }
|
||||
/** @deprecated quiz_cache collection has been dropped. */
|
||||
export async function setCachedQuiz() { return null; }
|
||||
|
||||
export async function getCachedQuiz(userId, weekNumber) {
|
||||
try {
|
||||
return await pb.collection('quiz_cache').getFirstListItem(
|
||||
`user_id="${userId}" && week_number=${weekNumber}`
|
||||
);
|
||||
} catch { return null; }
|
||||
}
|
||||
// ── Learn Progress (DEPRECATED — collection dropped) ────────────────────────
|
||||
|
||||
export function setCachedQuiz(userId, weekNumber, quiz) {
|
||||
const data = { questions: quiz.questions, meta: quiz.meta };
|
||||
return pbUpsert('quiz_cache', `user_id="${userId}" && week_number=${weekNumber}`,
|
||||
data, { user_id: userId, week_number: weekNumber, ...data });
|
||||
}
|
||||
|
||||
// ── Learn Progress ────────────────────────────────────────────────────────────
|
||||
|
||||
export async function getLearnDone(userId, weekNumber) {
|
||||
try {
|
||||
const r = await pb.collection('learn_progress').getFirstListItem(
|
||||
`user_id="${userId}" && week_number=${weekNumber}`
|
||||
);
|
||||
return r.done;
|
||||
} catch { return false; }
|
||||
}
|
||||
|
||||
export function setLearnDone(userId, weekNumber) {
|
||||
return pbUpsert('learn_progress', `user_id="${userId}" && week_number=${weekNumber}`,
|
||||
{ done: true }, { user_id: userId, week_number: weekNumber, done: true });
|
||||
}
|
||||
/** @deprecated learn_progress collection has been dropped. */
|
||||
export async function getLearnDone() { return false; }
|
||||
/** @deprecated learn_progress collection has been dropped. */
|
||||
export async function setLearnDone() { return null; }
|
||||
|
||||
// ── Leaderboard ───────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -391,14 +342,13 @@ export async function resetForSmokeTest({
|
||||
const collections = [
|
||||
'relations',
|
||||
'content',
|
||||
'quiz_banks',
|
||||
'quiz_results',
|
||||
'quiz_cache',
|
||||
'curriculum',
|
||||
'sources',
|
||||
'topics',
|
||||
'micro_learnings',
|
||||
'micro_learning_completions',
|
||||
];
|
||||
if (includeProgress) collections.push('learn_progress', 'leaderboard');
|
||||
if (includeProgress) collections.push('leaderboard');
|
||||
|
||||
const results = [];
|
||||
for (const name of collections) {
|
||||
|
||||
Reference in New Issue
Block a user