Files
CRM_Montzar/apps/api/src/conversations/conversations.controller.ts
T

94 lines
2.8 KiB
TypeScript
Raw Normal View History

import { Body, Controller, Get, Post, Query, 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,
HideConversationMessagesDto,
} 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('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,
);
}
@Post('messages/hide')
hideMessages(
@CurrentUser() user: { userId: string; organizationId: string; role: string },
@Body() dto: HideConversationMessagesDto,
) {
return this.conversations.hideMessages(
user.userId,
user.organizationId,
user.role,
dto.externalRoomId,
dto.messageIds,
dto.forEveryone !== false,
);
}
@Get('messages/hidden')
listHidden(
@CurrentUser() user: { userId: string; organizationId: string; role: string },
@Query('externalRoomId') externalRoomId: string,
) {
return this.conversations.listHiddenMessageIds(
user.userId,
user.organizationId,
user.role,
externalRoomId || '',
);
}
}