next/server/api/review/[revid]/index.get.ts
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ 088232f750
refactor(api & server/utils): refactor imports of db helpers
create an index file which exports the functions we need in one accessible place
2023-12-11 21:29:46 -05:00

18 lines
445 B
TypeScript

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