Skip to content

Commit

Permalink
Fix findPostById#withUser argument undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangvvo committed Sep 22, 2021
1 parent 7b11ef4 commit 0362d04
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions api-lib/db/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import { dbProjectionUsers } from './user';
export async function findPostById(db, id) {
const post = await db.collection('posts').findOne({ _id: id });
if (!post) return null;
if (withUser) {
post.creator = await db
.collection('users')
.findOne({ _id: post.creatorId }, { projection: dbProjectionUsers() });
}
post.creator = await db
.collection('users')
.findOne({ _id: post.creatorId }, { projection: dbProjectionUsers() });
return post;
}

Expand Down
2 changes: 1 addition & 1 deletion pages/user/[username]/post/[postId].jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function UserPost({ post }) {

export async function getServerSideProps(context) {
await nc().use(database).run(context.req, context.res);
const post = await findPostById(context.req.db, context.params.postId);
const post = await findPostById(context.req.db, context.params.postId, true);
if (!post) {
return {
notFound: true,
Expand Down

1 comment on commit 0362d04

@vercel
Copy link

@vercel vercel bot commented on 0362d04 Sep 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.