fix: sync bug
This commit is contained in:
@@ -38,8 +38,7 @@ export class DevicesController {
|
|||||||
@UseGuards(DeviceAuthGuard)
|
@UseGuards(DeviceAuthGuard)
|
||||||
@ApiOperation({ summary: 'Sync device state with server' })
|
@ApiOperation({ summary: 'Sync device state with server' })
|
||||||
async sync(@Param('deviceId') deviceId: string, @Body() dto: SyncDto, @Req() req: any) {
|
async sync(@Param('deviceId') deviceId: string, @Body() dto: SyncDto, @Req() req: any) {
|
||||||
const device = req.device;
|
return this.devicesService.sync(req.user, dto);
|
||||||
return this.devicesService.sync(device, dto);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post(':deviceId/commands/:commandId/ack')
|
@Post(':deviceId/commands/:commandId/ack')
|
||||||
@@ -51,8 +50,7 @@ export class DevicesController {
|
|||||||
@Body() dto: AckCommandDto,
|
@Body() dto: AckCommandDto,
|
||||||
@Req() req: any,
|
@Req() req: any,
|
||||||
) {
|
) {
|
||||||
const device = req.device;
|
return this.devicesService.ackCommand(req.user, commandId, dto);
|
||||||
return this.devicesService.ackCommand(device, commandId, dto);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('generation-code')
|
@Get('generation-code')
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ export class DevicesService {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
async sync(device: any, dto: SyncDto) {
|
async sync(device: any, dto: SyncDto) {
|
||||||
|
if (!device) {
|
||||||
|
throw new NotFoundException({ code: 'device_not_found', message: 'Device not found' });
|
||||||
|
}
|
||||||
if (device.revokedAt) {
|
if (device.revokedAt) {
|
||||||
throw new ForbiddenException({ code: 'device_revoked', message: 'Device has been revoked' });
|
throw new ForbiddenException({ code: 'device_revoked', message: 'Device has been revoked' });
|
||||||
}
|
}
|
||||||
@@ -150,6 +153,9 @@ export class DevicesService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async ackCommand(device: any, commandId: string, dto: AckCommandDto) {
|
async ackCommand(device: any, commandId: string, dto: AckCommandDto) {
|
||||||
|
if (!device) {
|
||||||
|
throw new NotFoundException({ code: 'device_not_found', message: 'Device not found' });
|
||||||
|
}
|
||||||
const command = await this.prisma.remoteCommand.findUnique({ where: { id: commandId } });
|
const command = await this.prisma.remoteCommand.findUnique({ where: { id: commandId } });
|
||||||
|
|
||||||
if (!command) {
|
if (!command) {
|
||||||
|
|||||||
Reference in New Issue
Block a user