next/server/api/band/[id]/index.get.ts

17 lines
355 B
TypeScript
Raw Normal View History

import { messages } from "@server/constants";
import { Band } from "@models/band";
export default eventHandler(async (ev) => {
const id = parseInt(getRouterParam(ev, "id") as string);
const band = await Band.findById(id).exec();
if (!band) {
throw createError({
statusCode: 404,
message: messages[404],
});
}
return band.toObject();
});