Skip to content

Commit

Permalink
fix: transform case and export client type
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <[email protected]>
  • Loading branch information
Innei committed Sep 2, 2024
1 parent da283b4 commit f7bce02
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
11 changes: 10 additions & 1 deletion apps/core/src/modules/activity/activity.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,16 @@ export class ActivityController {
readerIds.push(item.readerId)
}
}
const readers = await this.readerService.findReaderInIds(readerIds)
const readers = await this.readerService
.findReaderInIds(readerIds)
.then((arr) => {
return arr.map((item) => {
return snakecaseKeys({
...item,
id: item._id.toHexString(),
})
})
})

return {
data: keyBy(
Expand Down
8 changes: 8 additions & 0 deletions apps/core/src/modules/activity/activity.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { CommentService } from '../comment/comment.service'
import { ConfigsService } from '../configs/configs.service'
import { NoteService } from '../note/note.service'
import { PostService } from '../post/post.service'
import { ReaderService } from '../reader/reader.service'
import { Activity } from './activity.constant'
import { ActivityModel } from './activity.model'
import {
Expand Down Expand Up @@ -79,6 +80,7 @@ export class ActivityService implements OnModuleInit, OnModuleDestroy {
private readonly postService: PostService,
@Inject(forwardRef(() => NoteService))
private readonly noteService: NoteService,
private readonly readerService: ReaderService,
) {
this.logger = new Logger(ActivityService.name)
}
Expand Down Expand Up @@ -360,6 +362,12 @@ export class ActivityService implements OnModuleInit, OnModuleDestroy {

Reflect.deleteProperty(presenceData, 'ts')
const serializedPresenceData = omit(presenceData, 'ip')
if (data.readerId) {
const reader = await this.readerService.findReaderInIds([data.readerId])
if (reader.length) {
Object.assign(serializedPresenceData, { reader: reader[0] })
}
}

const roomJoinedAtMap =
await this.webGateway.getSocketRoomJoinedAtMap(socket)
Expand Down
6 changes: 5 additions & 1 deletion packages/api-client/controllers/activity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { IRequestAdapter } from '~/interfaces/adapter'
import type { IController } from '~/interfaces/controller'
import type { IRequestHandler } from '~/interfaces/request'
import type { AuthUser } from '~/models'
import type {
ActivityPresence,
LastYearPublication,
Expand Down Expand Up @@ -49,7 +50,10 @@ export class ActivityController<ResponseWrapper> implements IController {
* @support core >= 5.0.0
*/
getPresence(roomName: string) {
return this.proxy.presence.get<Record<string, ActivityPresence>>({
return this.proxy.presence.get<{
data: Record<string, ActivityPresence>
readers: Record<string, AuthUser>
}>({
params: {
room_name: roomName,
},
Expand Down
8 changes: 8 additions & 0 deletions packages/api-client/models/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface AuthUser {
id: string
email: string
isOwner: boolean
image: string
name: string
provider: string
}
1 change: 1 addition & 0 deletions packages/api-client/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './activity'
export * from './aggregate'
export * from './ai'
export * from './auth'
export * from './base'
export * from './category'
export * from './comment'
Expand Down

0 comments on commit f7bce02

Please sign in to comment.