79 lines
2.5 KiB
TypeScript
79 lines
2.5 KiB
TypeScript
import { Body, Controller, Get, Patch, Post, UseGuards } from '@nestjs/common';
|
|||
|
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||
|
|
import { CurrentUser } from '../auth/current-user.decorator';
|
||
|
|
import { RequireOrgModule } from '../billing/org-module.decorator';
|
||
|
|
import { OrgModuleGuard } from '../billing/org-module.guard';
|
||
|
|
import {
|
||
|
|
CreateConversationDmDto,
|
||
|
|
CreateConversationGroupDto,
|
||
|
|
UpdateConversationSettingsDto,
|
||
|
|
} from './dto';
|
||
|
|
import { ConversationsService } from './conversations.service';
|
||
|
|
|
||
|
|
@Controller('conversations')
|
||
|
|
@UseGuards(JwtAuthGuard, OrgModuleGuard)
|
||
|
|
@RequireOrgModule('conversations')
|
||
|
|
export class ConversationsController {
|
||
|
|
constructor(private readonly conversations: ConversationsService) {}
|
||
|
|
|
||
|
|
@Get('access')
|
||
|
|
access(@CurrentUser() user: { userId: string; organizationId: string; role: string }) {
|
||
|
|
return this.conversations.getAccess(user.userId, user.organizationId, user.role);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Get('settings')
|
||
|
|
settings(@CurrentUser() user: { organizationId: string; role: string }) {
|
||
|
|
return this.conversations.getSettings(user.organizationId);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Patch('settings')
|
||
|
|
updateSettings(
|
||
|
|
@CurrentUser() user: { organizationId: string; role: string },
|
||
|
|
@Body() dto: UpdateConversationSettingsDto,
|
||
|
|
) {
|
||
|
|
return this.conversations.updateSettings(user.organizationId, user.role, dto);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Get('session')
|
||
|
|
session(@CurrentUser() user: { userId: string; organizationId: string; role: string }) {
|
||
|
|
return this.conversations.getSession(user.userId, user.organizationId, user.role);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Get('peers')
|
||
|
|
peers(@CurrentUser() user: { userId: string; organizationId: string; role: string }) {
|
||
|
|
return this.conversations.listPeers(user.userId, user.organizationId, user.role);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Get('rooms')
|
||
|
|
rooms(@CurrentUser() user: { userId: string; organizationId: string; role: string }) {
|
||
|
|
return this.conversations.listRooms(user.userId, user.organizationId, user.role);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Post('rooms/dm')
|
||
|
|
createDm(
|
||
|
|
@CurrentUser() user: { userId: string; organizationId: string; role: string },
|
||
|
|
@Body() dto: CreateConversationDmDto,
|
||
|
|
) {
|
||
|
|
return this.conversations.createDm(
|
||
|
|
user.userId,
|
||
|
|
user.organizationId,
|
||
|
|
user.role,
|
||
|
|
dto.peerUserId,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Post('rooms/group')
|
||
|
|
createGroup(
|
||
|
|
@CurrentUser() user: { userId: string; organizationId: string; role: string },
|
||
|
|
@Body() dto: CreateConversationGroupDto,
|
||
|
|
) {
|
||
|
|
return this.conversations.createGroup(
|
||
|
|
user.userId,
|
||
|
|
user.organizationId,
|
||
|
|
user.role,
|
||
|
|
dto.name,
|
||
|
|
dto.memberUserIds,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|