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