☙◦ The Tablet ❀ GamerGirlandCo ◦❧
088232f750
create an index file which exports the functions we need in one accessible place
27 lines
759 B
TypeScript
27 lines
759 B
TypeScript
import { storyQuerier } from "~/lib/server/dbHelpers";
|
|
import { chapterTransformer } from "~/lib/server/dbHelpers";
|
|
import isLoggedIn from "~/lib/server/middlewareButNotReally/isLoggedIn";
|
|
import { messages } from "~/lib/server/constants";
|
|
|
|
export default eventHandler(async (ev) => {
|
|
isLoggedIn(ev);
|
|
const s = await storyQuerier(ev);
|
|
const hidden = s.chapters.some((a) => a.hidden);
|
|
if (
|
|
hidden &&
|
|
ev.context.currentUser?._id !== s.author._id &&
|
|
!ev.context.currentUser?.profile.isAdmin
|
|
) {
|
|
throw createError({
|
|
statusCode: 403,
|
|
message: messages[403],
|
|
});
|
|
}
|
|
const story = s.toObject();
|
|
|
|
for (let i = 0; i < story.chapters.length; i++) {
|
|
story.chapters[i] = (await chapterTransformer(s, ev, i)).currentChapter;
|
|
}
|
|
return story;
|
|
});
|