feat:update form

This commit is contained in:
2026-07-28 00:02:34 +07:00 Unverified
parent 0e8c816276
commit fa35f00f38
25 changed files with 919 additions and 149 deletions
+13 -2
View File
@@ -3,8 +3,8 @@
import { db } from "@/db";
import { unlink } from "fs/promises";
import path from "path";
import { questions } from "@/db/schema";
import type { QuestionType } from "@/db/schema";
import { cdn, questions } from "@/db/schema";
import type { ImageAnswerMode, QuestionType } from "@/db/schema";
import { eq } from "drizzle-orm";
import { revalidatePath } from "next/cache";
import { requireAdmin } from "@/lib/auth";
@@ -55,6 +55,7 @@ export async function updateQuestion(
options: string[];
imageUrl: string | null;
allowOther: boolean;
imageAnswerMode: ImageAnswerMode;
}>
) {
await requireAdmin();
@@ -91,6 +92,7 @@ export async function bulkUpdateQuestions(
displayOrder: number;
options: string[];
allowOther: boolean;
imageAnswerMode: ImageAnswerMode;
}[]
) {
await requireAdmin();
@@ -107,6 +109,7 @@ export async function bulkUpdateQuestions(
displayOrder: u.displayOrder,
options: u.options ?? [],
allowOther: u.allowOther,
imageAnswerMode: u.imageAnswerMode,
})
.where(eq(questions.id, u.id))
)
@@ -123,6 +126,14 @@ export async function bulkUpdateQuestions(
async function deleteImageFile(imageUrl: string | null) {
if (!imageUrl) return;
if (imageUrl.startsWith("/cdn/")) {
const id = imageUrl.split("/").pop();
if (id) {
await db.delete(cdn).where(eq(cdn.id, id));
}
return;
}
try {
const filename = imageUrl.split("/").pop();
if (filename) {