mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 20:54:53 +00:00
finished config with 6 scene device
This commit is contained in:
42
src/guards/scene.device.type.guard.ts
Normal file
42
src/guards/scene.device.type.guard.ts
Normal file
@ -0,0 +1,42 @@
|
||||
import { ProductType } from '@app/common/constants/product-type.enum';
|
||||
import {
|
||||
Injectable,
|
||||
CanActivate,
|
||||
ExecutionContext,
|
||||
BadRequestException,
|
||||
HttpException,
|
||||
} from '@nestjs/common';
|
||||
import { DeviceService } from 'src/device/services';
|
||||
|
||||
@Injectable()
|
||||
export class CheckFourAndSixSceneDeviceTypeGuard implements CanActivate {
|
||||
constructor(private readonly deviceService: DeviceService) {}
|
||||
|
||||
async canActivate(context: ExecutionContext): Promise<boolean> {
|
||||
const request = context.switchToHttp().getRequest();
|
||||
const deviceUuid = request.params.deviceUuid;
|
||||
|
||||
if (!deviceUuid) {
|
||||
throw new BadRequestException('Device UUID is required');
|
||||
}
|
||||
|
||||
try {
|
||||
const deviceDetails =
|
||||
await this.deviceService.getDeviceByDeviceUuid(deviceUuid);
|
||||
|
||||
if (
|
||||
deviceDetails.productDevice.prodType !== ProductType.FOUR_S &&
|
||||
deviceDetails.productDevice.prodType !== ProductType.SIX_S
|
||||
) {
|
||||
throw new BadRequestException('The device type is not supported');
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'An error occurred',
|
||||
error.status || 500,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user