next/server/api/band/[id]/stories.get.ts

29 lines
679 B
TypeScript

import { listQuerier } from "@server/dbHelpers";
import { Band } from "@models/band";
import { Story } from "@models/stories";
export default eventHandler(async (event) => {
const params = getRouterParams(event);
const query = getQuery(event);
let band = await Band.findById(params.id);
if (!band) {
throw createError({ statusCode: 404, message: "not found." });
}
let skipAmt = 20 * (parseInt((query.page as string) || "1") - 1) - 1;
if (skipAmt < 0) skipAmt = 0;
let stories = await listQuerier(
{
"chapters.bands": {
$in: [parseInt(params["id"])],
},
},
event.context,
event,
25,
); /* */
return {
...band.toObject(),
...stories,
};
});