Skip to content
/ core Public

Commit e60169a

Browse files
committed
fix(activity): enrich recent posts with category in getRecentPublish
1 parent 2961214 commit e60169a

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

apps/core/src/modules/activity/activity.service.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,9 +633,31 @@ export class ActivityService implements OnModuleInit, OnModuleDestroy {
633633
.toArray(),
634634
])
635635

636+
const postCategoryIds = post.map((p: any) => p.categoryId).filter(Boolean)
637+
const categories =
638+
postCategoryIds.length > 0
639+
? await this.databaseService.db
640+
.collection(CATEGORY_COLLECTION_NAME)
641+
.find({ _id: { $in: postCategoryIds } })
642+
.project({ slug: 1, name: 1 })
643+
.toArray()
644+
: []
645+
const categoryMap = Object.fromEntries(
646+
categories.map((c: any) => [
647+
c._id.toString(),
648+
{ slug: c.slug, name: c.name },
649+
]),
650+
)
651+
const enrichedPost = post.map((p: any) => ({
652+
...p,
653+
category: p.categoryId
654+
? (categoryMap[p.categoryId.toString()] ?? undefined)
655+
: undefined,
656+
}))
657+
636658
return {
637659
recent,
638-
post,
660+
post: enrichedPost,
639661
note,
640662
}
641663
}

packages/api-client/models/activity.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export interface RecentPost {
9393
title: string
9494
modified: string
9595
slug: string
96+
category?: { slug: string; name: string }
9697
}
9798

9899
export interface RecentRecent {

0 commit comments

Comments
 (0)