From 3ef566789e953f7df0f31c5104704bb60bd4a4c2 Mon Sep 17 00:00:00 2001 From: EpicUsername12 <39063367+EpicUsername12@users.noreply.github.com> Date: Tue, 30 May 2023 19:28:35 +0200 Subject: [PATCH] Hydrate Post documents on the aggregation path of ``/v1/communities/%s/posts`` --- src/services/api/routes/communities.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/services/api/routes/communities.ts b/src/services/api/routes/communities.ts index a576aef..334ced5 100644 --- a/src/services/api/routes/communities.ts +++ b/src/services/api/routes/communities.ts @@ -17,7 +17,7 @@ import { HydratedCommunityDocument } from '@/types/mongoose/community'; import { SubCommunityQuery } from '@/types/mongoose/subcommunity-query'; import { CommunityPostsQuery } from '@/types/mongoose/community-posts-query'; import { HydratedContentDocument } from '@/types/mongoose/content'; -import { HydratedPostDocument } from '@/types/mongoose/post'; +import {HydratedPostDocument, IPost} from '@/types/mongoose/post'; const createNewCommunitySchema = z.object({ name: z.string(), @@ -218,6 +218,7 @@ router.get('/:communityID/posts', async function (request: express.Request, resp { $replaceRoot: { newRoot: '$doc' } }, // replace the root with the 'doc' field { $limit: limit } // only return the top 10 results ]); + posts = posts.map((post: IPost) => Post.hydrate(post)); } else { posts = await Post.find(query).sort({ created_at: -1 }).limit(limit); }