forked from Chatbot/v3-api
28 lines
760 B
TypeScript
28 lines
760 B
TypeScript
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<boolean> {
|
|
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;
|
|
}
|
|
}
|