From 4ce4693e56a37438a7fa390de86af21008187ffa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Wed, 6 Dec 2023 21:22:52 -0500 Subject: [PATCH] feat(api): implement band editing --- server/api/band/[id]/index.put.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 server/api/band/[id]/index.put.ts diff --git a/server/api/band/[id]/index.put.ts b/server/api/band/[id]/index.put.ts new file mode 100644 index 0000000..2e5c9ba --- /dev/null +++ b/server/api/band/[id]/index.put.ts @@ -0,0 +1,29 @@ +import { messages } from "~/lib/server/constants"; +import isAdmin from "~/lib/server/middlewareButNotReally/isAdmin"; +import isLoggedIn from "~/lib/server/middlewareButNotReally/isLoggedIn"; +import { Band, IBand } from "~/models/band"; + +export default eventHandler(async (ev) => { + isAdmin(ev); + const id = parseInt(getRouterParam(ev, "id")!); + const body = await readBody>>(ev); + const data = await Band.findByIdAndUpdate( + id, + { + $set: { + ...body, + }, + }, + { new: true }, + ); + if (!data) { + throw createError({ + statusCode: 404, + message: messages[404], + }); + } + return { + success: true, + data, + }; +});