diff --git a/api/src/modules/chat/channels.service.ts b/api/src/modules/chat/channels.service.ts index 0f0d26e..11cb151 100644 --- a/api/src/modules/chat/channels.service.ts +++ b/api/src/modules/chat/channels.service.ts @@ -285,7 +285,10 @@ export class ChannelsService { }); channels.forEach((channel: any) => { - channel.lastMessage = channel.messages[0]; + if (channel.type === ChannelType.PUBLIC) { + channel.lastMessage = channel.messages[0]; + } + delete channel.messages; }); @@ -309,7 +312,10 @@ export class ChannelsService { // return the channel list without the password field // and with last message return channelUsers.map((cu: any) => { - cu.channel.lastMessage = cu.channel.messages[0]; + if (cu.channel.type === ChannelType.PUBLIC) { + cu.channel.lastMessage = cu.channel.messages[0]; + } + delete cu.channel.messages; // eslint-disable-next-line @typescript-eslint/no-unused-vars diff --git a/api/src/modules/chat/chat.controller.ts b/api/src/modules/chat/chat.controller.ts new file mode 100644 index 0000000..0688993 --- /dev/null +++ b/api/src/modules/chat/chat.controller.ts @@ -0,0 +1,17 @@ +import { Controller, Get, UseGuards } from '@nestjs/common'; +import { ApiBearerAuth } from '@nestjs/swagger'; + +import { JwtTwoFaAuthGuard } from '../auth'; +import { ChannelsService } from './channels.service'; + +@Controller('chat') +@UseGuards(JwtTwoFaAuthGuard) +@ApiBearerAuth() +export class ChatController { + constructor(private channelsService: ChannelsService) {} + + @Get('/channelList') + async getMyUser() { + return await this.channelsService.getChannelList(); + } +} diff --git a/api/src/modules/chat/chat.module.ts b/api/src/modules/chat/chat.module.ts index dd4e633..134f2ab 100644 --- a/api/src/modules/chat/chat.module.ts +++ b/api/src/modules/chat/chat.module.ts @@ -4,10 +4,11 @@ import { PrismaService } from '@/prisma'; import { UserService } from '../user'; import { ChannelsService } from './channels.service'; +import { ChatController } from './chat.controller'; import { ChatGateway } from './chat.gateway'; @Module({ - controllers: [], + controllers: [ChatController], providers: [ChatGateway, ChannelsService, PrismaService, UserService], }) export class ChatModule {}