forked from Chatbot/v3-api
first commit v3 initialiazed a temporary repository for darmanet client
This commit is contained in:
27
src/chat-attachments/attachment-session-expert.guard.ts
Normal file
27
src/chat-attachments/attachment-session-expert.guard.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user