next/server/api/story/[id]/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

16 lines
488 B
TypeScript

import { storyQuerier } from "~/lib/server/dbHelpers";
import storyCheck from "~/lib/server/middlewareButNotReally/storyCheck";
export default eventHandler(async (ev) => {
const story = await storyQuerier(ev);
let chrs = await storyCheck(ev, story, 0);
if (chrs != null) {
throw createError(chrs);
}
if (story.chapters.some((a) => a.loggedInOnly) && !ev.context.currentUser)
throw createError({
statusCode: 401,
message: "Authentication required",
});
return story;
});