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

165 lines
4.5 KiB
TypeScript
Raw Normal View History

import { Body, Controller, Delete, 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,
PinConversationMessageDto,
PinConversationRoomDto,
UnpinConversationMessageDto,
} 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('rooms/pin')
pinRoom(
@CurrentUser() user: { userId: string; organizationId: string; role: string },
@Body() dto: PinConversationRoomDto,
) {
return this.conversations.setRoomPinned(
user.userId,
user.organizationId,
user.role,
dto.externalRoomId,
dto.pinned,
);
}
@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 || '',
);
}
@Get('messages/pin')
getPinnedMessage(
@CurrentUser() user: { userId: string; organizationId: string; role: string },
@Query('externalRoomId') externalRoomId: string,
) {
return this.conversations.getPinnedMessage(
user.userId,
user.organizationId,
user.role,
externalRoomId || '',
);
}
@Post('messages/pin')
pinMessage(
@CurrentUser() user: { userId: string; organizationId: string; role: string },
@Body() dto: PinConversationMessageDto,
) {
return this.conversations.pinMessage(
user.userId,
user.organizationId,
user.role,
dto.externalRoomId,
dto.messageId,
dto.preview,
);
}
@Post('messages/unpin')
unpinMessage(
@CurrentUser() user: { userId: string; organizationId: string; role: string },
@Body() dto: UnpinConversationMessageDto,
) {
return this.conversations.unpinMessage(
user.userId,
user.organizationId,
user.role,
dto.externalRoomId,
);
}
@Delete('messages/pin')
unpinMessageDelete(
@CurrentUser() user: { userId: string; organizationId: string; role: string },
@Query('externalRoomId') externalRoomId: string,
) {
return this.conversations.unpinMessage(
user.userId,
user.organizationId,
user.role,
externalRoomId || '',
);
}
}