Skip to content
/ core Public

Commit 7dadc81

Browse files
committed
fix(activity): populate category in getRecentComment and expose in response
Include nested category populate for post refs and add category field to the returned comment objects so consumers can build correct post URLs.
1 parent 8c2afef commit 7dadc81

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import type { OnModuleDestroy, OnModuleInit } from '@nestjs/common'
22
import { forwardRef, Inject, Injectable, Logger } from '@nestjs/common'
3+
import { omit, pick, uniqBy } from 'es-toolkit/compat'
4+
import { ObjectId } from 'mongodb'
5+
import type { Document } from 'mongoose'
6+
import type { Socket } from 'socket.io'
7+
38
import { RequestContext } from '~/common/contexts/request.context'
49
import { BizException } from '~/common/exceptions/biz.exception'
510
import { ArticleTypeEnum } from '~/constants/article.constant'
@@ -21,10 +26,7 @@ import { transformDataToPaginate } from '~/transformers/paginate.transformer'
2126
import { checkRefModelCollectionType } from '~/utils/biz.util'
2227
import { dbTransforms } from '~/utils/db-transform.util'
2328
import { camelcaseKeys } from '~/utils/tool.util'
24-
import { omit, pick, uniqBy } from 'es-toolkit/compat'
25-
import { ObjectId } from 'mongodb'
26-
import type { Document } from 'mongoose'
27-
import type { Socket } from 'socket.io'
29+
2830
import { CommentState } from '../comment/comment.model'
2931
import { CommentService } from '../comment/comment.service'
3032
import { ConfigsService } from '../configs/configs.service'
@@ -540,7 +542,11 @@ export class ActivityService implements OnModuleInit, OnModuleDestroy {
540542
$in: [CommentState.Read, CommentState.Unread],
541543
},
542544
})
543-
.populate('ref', 'title nid slug subtitle content categoryId')
545+
.populate({
546+
path: 'ref',
547+
select: 'title nid slug subtitle content categoryId category',
548+
populate: { path: 'category', select: 'slug name' },
549+
})
544550
.lean({ getters: true })
545551
.sort({
546552
created: -1,
@@ -551,6 +557,7 @@ export class ActivityService implements OnModuleInit, OnModuleDestroy {
551557
return docs.map((doc) => ({
552558
...pick(doc, 'created', 'author', 'text', 'avatar'),
553559
...pick(doc.ref, 'title', 'nid', 'slug', 'id'),
560+
category: (doc.ref as any)?.category ?? undefined,
554561
type: checkRefModelCollectionType(doc.ref),
555562
}))
556563
}

packages/api-client/models/activity.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { CollectionRefTypes } from '@core/constants/db.constant'
2+
23
import type { CategoryModel } from './category'
34

45
export interface ActivityPresence {
@@ -66,6 +67,7 @@ export interface RecentComment {
6667
type: string
6768
avatar: string
6869
nid?: string
70+
category?: { slug: string; name: string }
6971
}
7072

7173
export interface RecentLike {

0 commit comments

Comments
 (0)