☙◦ The Tablet ❀ GamerGirlandCo ◦❧
ee7ea24e4e
change "bands" to "band" BREAKING CHANGE: breaks anything that tries to access `/api/bands/*`
29 lines
694 B
TypeScript
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,
|
|
};
|
|
});
|