mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-27 08:44:53 +00:00
Add automation module
This commit is contained in:
@ -14,7 +14,8 @@ import {
|
||||
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
|
||||
import {
|
||||
AddAutomationDto,
|
||||
UpdateSceneTapToRunDto,
|
||||
UpdateAutomationDto,
|
||||
UpdateAutomationStatusDto,
|
||||
} from '../dtos/automation.dto';
|
||||
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
||||
|
||||
@ -31,13 +32,13 @@ export class AutomationController {
|
||||
@Post()
|
||||
async addAutomation(@Body() addAutomationDto: AddAutomationDto) {
|
||||
try {
|
||||
const sceneAutomation =
|
||||
const automation =
|
||||
await this.automationService.addAutomation(addAutomationDto);
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'Automation added successfully',
|
||||
data: sceneAutomation,
|
||||
data: automation,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
@ -48,12 +49,12 @@ export class AutomationController {
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('tap-to-run/:unitUuid')
|
||||
async getTapToRunSceneByUnit(@Param('unitUuid') unitUuid: string) {
|
||||
@Get(':unitUuid')
|
||||
async getAutomationByUnit(@Param('unitUuid') unitUuid: string) {
|
||||
try {
|
||||
const tapToRunScenes =
|
||||
await this.automationService.getTapToRunSceneByUnit(unitUuid);
|
||||
return tapToRunScenes;
|
||||
const automation =
|
||||
await this.automationService.getAutomationByUnit(unitUuid);
|
||||
return automation;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
@ -63,51 +64,12 @@ export class AutomationController {
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Delete('tap-to-run/:unitUuid/:sceneId')
|
||||
async deleteTapToRunScene(
|
||||
@Param('unitUuid') unitUuid: string,
|
||||
@Param('sceneId') sceneId: string,
|
||||
) {
|
||||
@Get('details/:automationId')
|
||||
async getAutomationDetails(@Param('automationId') automationId: string) {
|
||||
try {
|
||||
await this.automationService.deleteTapToRunScene(unitUuid, sceneId);
|
||||
return {
|
||||
statusCode: HttpStatus.OK,
|
||||
message: 'Scene Deleted Successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('tap-to-run/trigger/:sceneId')
|
||||
async triggerTapToRunScene(@Param('sceneId') sceneId: string) {
|
||||
try {
|
||||
await this.automationService.triggerTapToRunScene(sceneId);
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'Scene trigger successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('tap-to-run/details/:sceneId')
|
||||
async getTapToRunSceneDetails(@Param('sceneId') sceneId: string) {
|
||||
try {
|
||||
const tapToRunScenes =
|
||||
await this.automationService.getTapToRunSceneDetails(sceneId);
|
||||
return tapToRunScenes;
|
||||
const automation =
|
||||
await this.automationService.getAutomationDetails(automationId);
|
||||
return automation;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
@ -118,21 +80,65 @@ export class AutomationController {
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Put('tap-to-run/:sceneId')
|
||||
async updateTapToRunScene(
|
||||
@Body() updateSceneTapToRunDto: UpdateSceneTapToRunDto,
|
||||
@Param('sceneId') sceneId: string,
|
||||
@Delete(':unitUuid/:automationId')
|
||||
async deleteAutomation(
|
||||
@Param('unitUuid') unitUuid: string,
|
||||
@Param('automationId') automationId: string,
|
||||
) {
|
||||
try {
|
||||
const tapToRunScene = await this.automationService.updateTapToRunScene(
|
||||
updateSceneTapToRunDto,
|
||||
sceneId,
|
||||
await this.automationService.deleteAutomation(unitUuid, automationId);
|
||||
return {
|
||||
statusCode: HttpStatus.OK,
|
||||
message: 'Automation Deleted Successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Put(':automationId')
|
||||
async updateAutomation(
|
||||
@Body() updateAutomationDto: UpdateAutomationDto,
|
||||
@Param('automationId') automationId: string,
|
||||
) {
|
||||
try {
|
||||
const automation = await this.automationService.updateAutomation(
|
||||
updateAutomationDto,
|
||||
automationId,
|
||||
);
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'Scene updated successfully',
|
||||
data: tapToRunScene,
|
||||
message: 'Automation updated successfully',
|
||||
data: automation,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Put('status/:automationId')
|
||||
async updateAutomationStatus(
|
||||
@Body() updateAutomationStatusDto: UpdateAutomationStatusDto,
|
||||
@Param('automationId') automationId: string,
|
||||
) {
|
||||
try {
|
||||
await this.automationService.updateAutomationStatus(
|
||||
updateAutomationStatusDto,
|
||||
automationId,
|
||||
);
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'Automation status updated successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
|
||||
Reference in New Issue
Block a user