Browse Source

Merge branch 'chat-users' into 'stage'

CHORE | Get users list to add to chat members

See merge request jetup/rws/api-rws!239
merge-requests/240/merge
Coder 2 years ago
parent
commit
ae52aff6ce
  1. 3
      src/rest/app/chats/chats.module.ts
  2. 25
      src/rest/app/chats/controllers/app-chats.controller.ts
  3. 1
      src/rest/app/chats/dto/index.ts
  4. 31
      src/rest/app/chats/dto/potential-chat-members.dto.ts
  5. 43
      src/rest/app/chats/services/app-chats.service.ts

3
src/rest/app/chats/chats.module.ts

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
import { DynamicModule, Module } from '@nestjs/common'
import { ChatsModule, RealTimeModule } from 'src/domain'
import { ChatsModule, RealTimeModule, UsersModule } from 'src/domain'
import { JwtModule } from 'src/libs'
import {
AppChatsController,
@ -17,6 +17,7 @@ export class AppChatsModule { @@ -17,6 +17,7 @@ export class AppChatsModule {
JwtModule.forFeature(),
ChatsModule.forFeature(),
RealTimeModule.forFeature(),
UsersModule.forFeature(),
],
providers: [AppChatsService, AppChatsMessagesService, AppChatsMembersService],
controllers: [

25
src/rest/app/chats/controllers/app-chats.controller.ts

@ -24,7 +24,13 @@ import { ChatDetailsDto, ChatsListDto } from 'src/core/dto' @@ -24,7 +24,13 @@ import { ChatDetailsDto, ChatsListDto } from 'src/core/dto'
import { IPagination } from 'src/core/interfaces'
import { AuthGuard } from 'src/domain/sessions/decorators'
import { ApiImplictPagination, ReqPagination, ReqUser } from 'src/shared'
import { SetChatMutedDto, StoreGroupChatDto, StorePersonalChatDto, UpdateChatDto } from '../dto'
import {
PotentialMembersListDto,
SetChatMutedDto,
StoreGroupChatDto,
StorePersonalChatDto,
UpdateChatDto,
} from '../dto'
import { AppChatsService } from '../services'
@ApiTags('App | Chats')
@ -123,6 +129,23 @@ export class AppChatsController { @@ -123,6 +129,23 @@ export class AppChatsController {
/*************************************************************************************** */
@ApiOperation({
summary: 'Отримання списку користувачів, що можуть стати учасниками групового чату',
})
@ApiOkResponse({
description: 'Повертає список імен користувачів',
isArray: true,
type: PotentialMembersListDto,
})
@ApiImplictPagination()
@AuthGuard()
@Get('users')
public async getUsersForChat(@ReqPagination() pagination: IPagination) {
return this.chatsService.getUsersForChat(pagination)
}
/*************************************************************************************** */
@ApiOperation({
summary: 'Отримання чату з учасниками',
})

1
src/rest/app/chats/dto/index.ts

@ -11,3 +11,4 @@ export * from './unread-messages-count.dto' @@ -11,3 +11,4 @@ export * from './unread-messages-count.dto'
export * from './export-chat-messages.dto'
export * from './delete-chat-member.dto'
export * from './delete-message.dto'
export * from './potential-chat-members.dto'

31
src/rest/app/chats/dto/potential-chat-members.dto.ts

@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
import { IsString } from 'class-validator'
import { DtoProperty } from 'src/shared'
export class PotentialMemberDto {
@DtoProperty()
@IsString()
userId: number
@DtoProperty()
@IsString()
firstName: string
@DtoProperty()
@IsString()
lastName: string
@DtoProperty()
@IsString()
avatarUrl: string
}
export class PotentialMembersListDto {
@DtoProperty({
isArray: true,
type: PotentialMemberDto,
})
items: PotentialMemberDto[]
@DtoProperty()
count: number
}

43
src/rest/app/chats/services/app-chats.service.ts

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
import { Inject, Injectable } from '@nestjs/common'
import * as _ from 'lodash'
import { Chats, FilesStorage, WebSockets } from 'src/core'
import { Chats, FilesStorage, Users, WebSockets } from 'src/core'
import {
CHATS_MEMBERS_SERVICE,
CHATS_MESSAGES_SERVICE,
@ -8,23 +8,24 @@ import { @@ -8,23 +8,24 @@ import {
CHATS_SYSTEM_MESSAGES_SERVICE,
GET_CHATS_LIST_ACTION,
REAL_TIME_SERVICE,
USERS_SERVICE,
} from 'src/core/consts'
import { IPagination } from 'src/core/interfaces'
import { transformFileUrl } from 'src/shared/transforms'
import { SetChatMutedDto, StoreGroupChatDto, StorePersonalChatDto, UpdateChatDto } from '../dto'
@Injectable()
export class AppChatsService {
constructor(
@Inject(CHATS_SERVICE) private readonly chatsService: Chats.IChatsService,
@Inject(CHATS_MESSAGES_SERVICE)
private readonly chatsMessagesService: Chats.IChatsMessagesService,
@Inject(CHATS_SYSTEM_MESSAGES_SERVICE)
private readonly chatsSystemMessagesService: Chats.IChatsSystemMessagesService,
@Inject(CHATS_MEMBERS_SERVICE)
private readonly chatsMembersService: Chats.IChatsMembersService,
@Inject(REAL_TIME_SERVICE) private wsService: WebSockets.Service,
@Inject(GET_CHATS_LIST_ACTION) private getChatsListAction: Chats.IGetChatsListAction,
) {}
@Inject(CHATS_SERVICE) private readonly chatsService: Chats.IChatsService
@Inject(CHATS_MESSAGES_SERVICE)
private readonly chatsMessagesService: Chats.IChatsMessagesService
@Inject(CHATS_SYSTEM_MESSAGES_SERVICE)
private readonly chatsSystemMessagesService: Chats.IChatsSystemMessagesService
@Inject(CHATS_MEMBERS_SERVICE)
private readonly chatsMembersService: Chats.IChatsMembersService
@Inject(REAL_TIME_SERVICE) private wsService: WebSockets.Service
@Inject(GET_CHATS_LIST_ACTION) private getChatsListAction: Chats.IGetChatsListAction
@Inject(USERS_SERVICE) private readonly usersService: Users.IUsersService
public async storeGroupChat(
userId: number,
@ -103,6 +104,24 @@ export class AppChatsService { @@ -103,6 +104,24 @@ export class AppChatsService {
chatUsersIds.map(it => this.wsService.emitToUser(it, 'chat/delete-chat', { chatId }))
}
public async getUsersForChat(pagination: IPagination) {
const { items, count } = await this.usersService.getList(pagination, {})
const reducedUsers = items.map(user => {
const reducedUser = _.pick(user.info, ['userId', 'firstName', 'middleName', 'lastName'])
return {
...reducedUser,
avatarUrl: transformFileUrl(user.info.avatarUrl),
}
})
return {
items: reducedUsers,
count,
}
}
private async restoreMemberIfDeleted(userId: number, members: Chats.IChatMember[]) {
const member = _.find(members, member => member.userId === userId)
if (!member.isDeleted) return

Loading…
Cancel
Save