import { CanActivate, ExecutionContext, Injectable, UnauthorizedException, } from '@nestjs/common'; import { ChatService } from 'src/socket/support-management/chat.service'; @Injectable() export class AttachmentSessionExpertGuard 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 admin = req.admin; if (!admin?._id) { throw new UnauthorizedException('expert_token_required'); } await this.chatService.assertParticipantCanUploadVoice( sessionId, String(admin._id), 'Expert', ); return true; } }