feat(api): add endpoints for retrieving a band's info and its associated stories

This commit is contained in:
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ 2023-10-03 00:48:41 -04:00
parent 66d6168a31
commit 8070e8c555
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C
2 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,8 @@
import { Band } from "~/models/band";
export default eventHandler(async (ev) => {
const id = parseInt(getRouterParam(ev, "id") as string);
const band = await Band.findById(id).exec();
return band;
});

View File

@ -0,0 +1,28 @@
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,
); /* */
console.log(skipAmt);
return {
...band.toObject(),
stories: stories /* .slice(skipAmt, skipAmt + 20 + 1) */,
total: stories.length,
};
});