import { CanActivate, ExecutionContext, Injectable, UnauthorizedException, } from '@nestjs/common'; import { ChatService } from 'src/socket/support-management/chat.service'; @Injectable() export class AttachmentSessionUserGuard implements CanActivate { constructor(private readonly chatService: ChatService) {} async canActivate(context: ExecutionContext): Promise { const req = context.switchToHttp().getRequest(); const sessionId = req.params?.sessionId as string; const user = req.user; if (!user?._id) { throw new UnauthorizedException('user_token_required'); } await this.chatService.assertParticipantCanUploadVoice( sessionId, String(user._id), 'User', ); return true; } }