initialize project with basic structure and dependencies
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { db } from "../../db/index";
|
||||
import { uploads } from "../../db/schema";
|
||||
import { eq } from "drizzle-orm";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const id = getRouterParam(event, "id")!;
|
||||
|
||||
const upload = await db.query.uploads.findFirst({ where: eq(uploads.id, id) });
|
||||
if (!upload) throw createError({ statusCode: 404, message: "Upload not found" });
|
||||
|
||||
const body = await readBody(event);
|
||||
const { type } = body ?? {};
|
||||
|
||||
const valid = ["slides", "past_paper", "lab_worksheet"];
|
||||
if (!type || !valid.includes(type)) {
|
||||
throw createError({ statusCode: 400, message: "type must be slides, past_paper, or lab_worksheet" });
|
||||
}
|
||||
|
||||
await db
|
||||
.update(uploads)
|
||||
.set({ type: type as "slides" | "past_paper" | "lab_worksheet" })
|
||||
.where(eq(uploads.id, id));
|
||||
|
||||
return { ok: true, type };
|
||||
});
|
||||
Reference in New Issue
Block a user