first commit v3 initialiazed a temporary repository for darmanet client

This commit is contained in:
2026-09-08 16:04:01 +03:30
commit 5c7fd95052
216 changed files with 30050 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
import { Injectable, CanActivate, ExecutionContext } from '@nestjs/common';
import { WsException } from '@nestjs/websockets';
import { Socket } from 'socket.io';
import { BusinessHoursService } from '../business-hours.service';
import { createSocketResponse } from 'src/socket/support-management/dto/eventPayloads.dto';
import { HttpStatus } from '@nestjs/common';
@Injectable()
export class BusinessHoursGuard implements CanActivate {
constructor(private readonly businessHoursService: BusinessHoursService) {}
async canActivate(context: ExecutionContext): Promise<boolean> {
const client = context.switchToWs().getClient<Socket>();
const status = await this.businessHoursService.isOpen();
const nextOpen = await this.businessHoursService.getNextOpen();
if (!status.open) {
const message =
status.reason ||
'Online conversation is not available now. Please try again later.';
const errorResponse = createSocketResponse(
'ONLINE_CONVERSATION_DISABLED',
{
code: 'ONLINE_CONVERSATION_DISABLED',
message,
nextOpen: nextOpen?.toISOString() || null,
},
message,
HttpStatus.SERVICE_UNAVAILABLE,
);
client.emit('response', errorResponse);
throw new WsException({
code: 'ONLINE_CONVERSATION_DISABLED',
message,
nextOpen: nextOpen?.toISOString() || null,
});
}
return true;
}
}