2023-10-03 00:52:24 -04:00
|
|
|
import type { H3Event, EventHandlerRequest } from "h3";
|
2023-12-20 17:23:31 -05:00
|
|
|
import { Challenge } from "@models/challenges/gen";
|
|
|
|
import { Story } from "@models/stories";
|
2023-12-29 16:39:41 -05:00
|
|
|
import { isIdNan } from "@server/middlewareButNotReally";
|
2023-10-03 00:52:24 -04:00
|
|
|
export default async function (ev: H3Event<EventHandlerRequest>) {
|
2023-12-20 17:23:31 -05:00
|
|
|
const id = isIdNan(ev);
|
2023-10-03 00:52:24 -04:00
|
|
|
const chapterIndex = ev.context.chapterIndex;
|
|
|
|
if (isNaN(id) || isNaN(chapterIndex))
|
|
|
|
throw createError({
|
|
|
|
statusCode: 404,
|
|
|
|
message: "Not found.",
|
|
|
|
});
|
|
|
|
const story = await Story.findById(id)
|
|
|
|
.populate("author", "username profile blocked")
|
2023-10-11 15:31:02 -04:00
|
|
|
.populate("coAuthor", "username profile")
|
2023-10-03 00:52:24 -04:00
|
|
|
.populate("chapters.bands")
|
|
|
|
.populate({
|
|
|
|
path: "ficmas",
|
|
|
|
populate: { path: "wisher", select: "_id username" },
|
|
|
|
})
|
|
|
|
.populate({ path: "challenge", model: Challenge })
|
|
|
|
.exec();
|
2023-12-09 17:01:13 -05:00
|
|
|
if (story == null)
|
|
|
|
throw createError({ statusCode: 404, message: "Not found." });
|
2023-10-03 00:52:24 -04:00
|
|
|
return story;
|
|
|
|
}
|