next/server/api/band/[id]/stories.get.ts
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ ee7ea24e4e
refactor(*): rename route
change "bands" to "band"

BREAKING CHANGE: breaks anything that tries to access `/api/bands/*`
2023-12-06 22:22:48 -05:00

29 lines
694 B
TypeScript

import listQuerier from "~/lib/server/dbHelpers/listQuerier";
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,
};
});