29 lines
564 B
TypeScript
29 lines
564 B
TypeScript
import { messages } from "@server/constants";
|
|
import { isAdmin } from "@server/middlewareButNotReally";
|
|
import { Band, IBand } from "@models/band";
|
|
|
|
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,
|
|
};
|
|
});
|