next/server/api/band/[id]/stories.get.ts
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ 088232f750
refactor(api & server/utils): refactor imports of db helpers
create an index file which exports the functions we need in one accessible place
2023-12-11 21:29:46 -05:00

29 lines
686 B
TypeScript

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