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

16 lines
424 B
TypeScript
Raw Normal View History

import { messages } from "@server/constants";
import { Review } from "@models/stories/review";
import { isIdNan } from "@server/middlewareButNotReally";
export default eventHandler(async (ev) => {
const revid = isIdNan(ev);
2023-12-29 20:53:29 -05:00
const r = await Review.findById(revid).populate("author", "username _id").exec();
if (!r) {
throw createError({
statusCode: 404,
message: messages[404],
});
}
return r.toObject();
});