feat:update form
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user