refactor(server/utils): make the chapter index parameter in the chapterTransformer function mandatory

This commit is contained in:
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ 2023-12-01 17:57:17 -05:00
parent e69965f6ec
commit d5de2499ab
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C

View File

@ -5,12 +5,13 @@ import { stringifyStream } from "~/lib/functions";
import { IStory } from "~/models/stories"; import { IStory } from "~/models/stories";
import { IChapter } from "~/models/stories/chapter"; import { IChapter } from "~/models/stories/chapter";
import getBucket from "../storyHelpers/getBucket"; import getBucket from "../storyHelpers/getBucket";
import { SingleChapterResult } from "~/lib/client/types/slightlyDifferentStory";
export default async function ( export default async function (
story: Document<number, {}, IStory> & IStory, story: Document<number, {}, IStory> & IStory,
event: H3Event<EventHandlerRequest>, event: H3Event<EventHandlerRequest>,
cindex?: number, cindex: number,
) { ): Promise<SingleChapterResult> {
const finObj: any = story.toObject(); const finObj: any = story.toObject();
const cloned: any & { chapters: IChapter[] } = { ...finObj }; const cloned: any & { chapters: IChapter[] } = { ...finObj };
delete finObj.chapters; delete finObj.chapters;
@ -30,5 +31,6 @@ export default async function (
.replace(/<p><br\s\/><b\s\/><\/p>/gm, ""), .replace(/<p><br\s\/><b\s\/><\/p>/gm, ""),
}; };
finObj.totalChapters = story.chapters.length; finObj.totalChapters = story.chapters.length;
finObj.chapterNames = story.chapters.map((a) => a.title);
return finObj; return finObj;
} }