diff --git a/components/story/create/singleChapter.vue b/components/story/create/singleChapter.vue index 6938882..ae05707 100644 --- a/components/story/create/singleChapter.vue +++ b/components/story/create/singleChapter.vue @@ -22,7 +22,7 @@ data: FormChapter; }>(); let acData = toRef(data); - let { data: _bands } = await useApiFetch("/bands/all"); + let { data: _bands } = await useApiFetch("/band/all"); let bands = ref(_bands); provide("curName", name + "."); provide("bandlist", bands); diff --git a/pages/band/[id].vue b/pages/band/[id].vue index 16b1af8..05fffee 100644 --- a/pages/band/[id].vue +++ b/pages/band/[id].vue @@ -2,10 +2,9 @@ import storyList from "~/components/listings/stories.vue"; import { IBand } from "~/models/band"; const route = useRoute(); - const { data: band } = await useApiFetch(`/bands/${route.params.id}`); - const pref = `/bands/${route.params.id}/stories`; + const { data: band } = await useApiFetch(`/band/${route.params.id}`); diff --git a/server/api/bands/[id]/index.get.ts b/server/api/band/[id]/index.get.ts similarity index 53% rename from server/api/bands/[id]/index.get.ts rename to server/api/band/[id]/index.get.ts index 951f985..7574bc5 100644 --- a/server/api/bands/[id]/index.get.ts +++ b/server/api/band/[id]/index.get.ts @@ -1,8 +1,16 @@ +import { messages } from "~/lib/server/constants"; 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; + if (!band) { + throw createError({ + statusCode: 404, + message: messages[404], + }); + } + + return band.toObject(); }); diff --git a/server/api/bands/[id]/stories.get.ts b/server/api/band/[id]/stories.get.ts similarity index 88% rename from server/api/bands/[id]/stories.get.ts rename to server/api/band/[id]/stories.get.ts index ddb7809..251817a 100644 --- a/server/api/bands/[id]/stories.get.ts +++ b/server/api/band/[id]/stories.get.ts @@ -18,10 +18,11 @@ export default eventHandler(async (event) => { }, }, event.context, + event, + 25, ); /* */ return { ...band.toObject(), - stories: stories /* .slice(skipAmt, skipAmt + 20 + 1) */, - total: stories.length, + ...stories, }; }); diff --git a/server/api/bands/all.get.ts b/server/api/band/all.get.ts similarity index 100% rename from server/api/bands/all.get.ts rename to server/api/band/all.get.ts