feat: exam actions and data safety fixes

This commit is contained in:
SpecialX
2025-12-30 17:48:22 +08:00
parent e7c902e8e1
commit f7ff018490
27 changed files with 896 additions and 194 deletions

View File

@@ -9,6 +9,7 @@ import { cache } from "react";
export type GetQuestionsParams = {
page?: number;
pageSize?: number;
ids?: string[];
knowledgePointId?: string;
difficulty?: number;
};
@@ -18,6 +19,7 @@ export type GetQuestionsParams = {
export const getQuestions = cache(async ({
page = 1,
pageSize = 10,
ids,
knowledgePointId,
difficulty,
}: GetQuestionsParams = {}) => {
@@ -26,6 +28,10 @@ export const getQuestions = cache(async ({
// Build Where Conditions
const conditions = [];
if (ids && ids.length > 0) {
conditions.push(inArray(questions.id, ids));
}
if (difficulty) {
conditions.push(eq(questions.difficulty, difficulty));
}
@@ -40,9 +46,9 @@ export const getQuestions = cache(async ({
conditions.push(inArray(questions.id, subQuery));
}
// Only fetch top-level questions (parent questions)
// Assuming we only want to list "root" questions, not sub-questions
conditions.push(sql`${questions.parentId} IS NULL`);
if (!ids || ids.length === 0) {
conditions.push(sql`${questions.parentId} IS NULL`)
}
const whereClause = conditions.length > 0 ? and(...conditions) : undefined;