Files
prosapp-migration/backend/src/chat/chat.controller.ts
T

39 lines
1.1 KiB
TypeScript

import { Controller, Get, Post, Param, Body, UseGuards, Req } from '@nestjs/common';
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
import { ChatService } from './chat.service';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
@ApiTags('Chat')
@Controller('chat')
export class ChatController {
constructor(private chat: ChatService) {}
@Post('start/:professionalId')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
start(@Req() req, @Param('professionalId') professionalId: string) {
return this.chat.getOrCreateChat(req.user.sub, professionalId);
}
@Post(':chatId/message')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
sendMessage(@Req() req, @Param('chatId') chatId: string, @Body() dto: { content: string }) {
return this.chat.sendMessage(chatId, req.user.sub, dto.content);
}
@Get('my')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
myChats(@Req() req) {
return this.chat.getUserChats(req.user.sub);
}
@Get(':chatId/messages')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
messages(@Param('chatId') chatId: string) {
return this.chat.getChatMessages(chatId);
}
}