feat: exam actions and data safety fixes
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user