Skip to content

Commit

Permalink
add route for channel list
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilaboz committed Nov 15, 2023
1 parent cbaf9f8 commit 17ee645
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
10 changes: 8 additions & 2 deletions api/src/modules/chat/channels.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});

Expand All @@ -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
Expand Down
17 changes: 17 additions & 0 deletions api/src/modules/chat/chat.controller.ts
Original file line number Diff line number Diff line change
@@ -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();
}
}
3 changes: 2 additions & 1 deletion api/src/modules/chat/chat.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

0 comments on commit 17ee645

Please sign in to comment.