shack/pages/posts/post.page.server.js

28 lines
624 B
JavaScript
Raw Normal View History

2023-06-11 03:32:02 +00:00
import { fetchShelf } from '../../src/shelves';
import { fetchPost } from '../../src/posts';
import { fetchPostComments } from '../../src/comments';
async function getPageData(pageContext) {
const [shelf, post, comments] = await Promise.all([
2023-06-25 17:52:00 +00:00
fetchShelf(pageContext.routeParams.shelfId),
fetchPost(pageContext.routeParams.postId, pageContext.session.user),
2023-06-11 03:32:02 +00:00
fetchPostComments(pageContext.routeParams.postId),
]);
if (!shelf) {
2023-06-25 17:52:00 +00:00
throw new Error('This shelf does not exist');
2023-06-11 03:32:02 +00:00
}
if (!post) {
2023-06-25 17:52:00 +00:00
throw new Error('This post does not exist');
2023-06-11 03:32:02 +00:00
}
return {
shelf,
post,
comments,
};
}
export { getPageData };