2023-12-20 17:23:31 -05:00
|
|
|
import { messages } from "@server/constants";
|
2023-12-29 16:32:32 -05:00
|
|
|
import { isAdmin } from "@server/middlewareButNotReally";
|
2023-12-20 17:23:31 -05:00
|
|
|
import { Band, IBand } from "@models/band";
|
2023-12-06 21:22:52 -05:00
|
|
|
|
|
|
|
export default eventHandler(async (ev) => {
|
|
|
|
isAdmin(ev);
|
|
|
|
const id = parseInt(getRouterParam(ev, "id")!);
|
|
|
|
const body = await readBody<Partial<Omit<IBand, "_id">>>(ev);
|
|
|
|
const data = await Band.findByIdAndUpdate(
|
|
|
|
id,
|
|
|
|
{
|
|
|
|
$set: {
|
|
|
|
...body,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{ new: true },
|
|
|
|
);
|
|
|
|
if (!data) {
|
|
|
|
throw createError({
|
|
|
|
statusCode: 404,
|
|
|
|
message: messages[404],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
success: true,
|
|
|
|
data,
|
|
|
|
};
|
|
|
|
});
|