import { chapterTransformer } from "@server/dbHelpers";
import { storyQuerier } from "@server/dbHelpers";
import { storyCheck } from "@server/middlewareButNotReally";

export default eventHandler(async (ev) => {
	const story = await storyQuerier(ev);
	const bi = parseInt(getRouterParam(ev, "chapter")!);
	const chres = await storyCheck(ev, story, bi - 1);
	if (chres != null) {
		throw createError(chres);
	}
	return await chapterTransformer(story, ev, bi - 1);
});
