Forráskód Böngészése

✨ feat(user): 添加用户关注统计属性

- 新增followerCount计算属性,返回用户关注者数量
- 新增followingCount计算属性,返回用户关注的数量
- 在UserSchema中添加对应字段的OpenAPI文档描述和示例值
yourname 5 hónapja
szülő
commit
5cdbf3e3da
1 módosított fájl, 16 hozzáadás és 0 törlés
  1. 16 0
      src/server/modules/users/user.entity.ts

+ 16 - 0
src/server/modules/users/user.entity.ts

@@ -64,6 +64,14 @@ export class UserEntity {
   constructor(partial?: Partial<UserEntity>) {
     Object.assign(this, partial);
   }
+
+  get followerCount(): number {
+    return this.followers?.length || 0;
+  }
+
+  get followingCount(): number {
+    return this.following?.length || 0;
+  }
 }
 
 export const UserSchema = z.object({
@@ -122,6 +130,14 @@ export const UserSchema = z.object({
     ],
     description: '用户角色列表'
   }),
+  followerCount: z.number().int().nonnegative().openapi({
+    description: '关注者数量',
+    example: 100
+  }),
+  followingCount: z.number().int().nonnegative().openapi({
+    description: '关注的用户数量',
+    example: 50
+  }),
   createdAt: z.date().openapi({ description: '创建时间' }),
   updatedAt: z.date().openapi({ description: '更新时间' })
 });