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 */ }
|
} catch { /* no record, nothing to do */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Quiz Banks ───────────────────────────────────────────────────────────────
|
// ── Quiz Banks (DEPRECATED — collection dropped) ────────────────────────────
|
||||||
|
|
||||||
function normalizeQuizQuestion(q) {
|
/** @deprecated quiz_banks collection has been dropped. */
|
||||||
if (!q || typeof q !== 'object') return q;
|
export async function getQuizBank() { return []; }
|
||||||
return q.difficulty ? q : { ...q, difficulty: 'medium' };
|
/** @deprecated quiz_banks collection has been dropped. */
|
||||||
}
|
export async function setQuizBank() { return null; }
|
||||||
|
/** @deprecated quiz_banks collection has been dropped. */
|
||||||
export async function getQuizBank(topicId) {
|
export async function deleteQuestionFromBank() { return null; }
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Sources ──────────────────────────────────────────────────────────────────
|
// ── Sources ──────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
@@ -173,61 +159,26 @@ export async function deleteTeamMember(id) {
|
|||||||
return pb.collection('team_members').delete(id);
|
return pb.collection('team_members').delete(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Quiz Results ─────────────────────────────────────────────────────────────
|
// ── Quiz Results (DEPRECATED — collection dropped) ──────────────────────────
|
||||||
|
|
||||||
export async function getQuizResult(userId, weekNumber) {
|
/** @deprecated quiz_results collection has been dropped. */
|
||||||
try {
|
export async function getQuizResult() { return null; }
|
||||||
return await pb.collection('quiz_results').getFirstListItem(
|
/** @deprecated quiz_results collection has been dropped. */
|
||||||
`user_id="${userId}" && week_number=${weekNumber}`
|
export async function saveQuizResult() { return null; }
|
||||||
);
|
|
||||||
} catch { return null; }
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function saveQuizResult(userId, weekNumber, result) {
|
// ── Quiz Cache (DEPRECATED — collection dropped) ────────────────────────────
|
||||||
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 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) {
|
// ── Learn Progress (DEPRECATED — collection dropped) ────────────────────────
|
||||||
try {
|
|
||||||
return await pb.collection('quiz_cache').getFirstListItem(
|
|
||||||
`user_id="${userId}" && week_number=${weekNumber}`
|
|
||||||
);
|
|
||||||
} catch { return null; }
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setCachedQuiz(userId, weekNumber, quiz) {
|
/** @deprecated learn_progress collection has been dropped. */
|
||||||
const data = { questions: quiz.questions, meta: quiz.meta };
|
export async function getLearnDone() { return false; }
|
||||||
return pbUpsert('quiz_cache', `user_id="${userId}" && week_number=${weekNumber}`,
|
/** @deprecated learn_progress collection has been dropped. */
|
||||||
data, { user_id: userId, week_number: weekNumber, ...data });
|
export async function setLearnDone() { return null; }
|
||||||
}
|
|
||||||
|
|
||||||
// ── 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 });
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Leaderboard ───────────────────────────────────────────────────────────────
|
// ── Leaderboard ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
@@ -391,14 +342,13 @@ export async function resetForSmokeTest({
|
|||||||
const collections = [
|
const collections = [
|
||||||
'relations',
|
'relations',
|
||||||
'content',
|
'content',
|
||||||
'quiz_banks',
|
|
||||||
'quiz_results',
|
|
||||||
'quiz_cache',
|
|
||||||
'curriculum',
|
'curriculum',
|
||||||
'sources',
|
'sources',
|
||||||
'topics',
|
'topics',
|
||||||
|
'micro_learnings',
|
||||||
|
'micro_learning_completions',
|
||||||
];
|
];
|
||||||
if (includeProgress) collections.push('learn_progress', 'leaderboard');
|
if (includeProgress) collections.push('leaderboard');
|
||||||
|
|
||||||
const results = [];
|
const results = [];
|
||||||
for (const name of collections) {
|
for (const name of collections) {
|
||||||
|
|||||||
Reference in New Issue
Block a user