added exception filter and removed controller error handling

This commit is contained in:
unknown
2024-10-06 11:04:25 +03:00
26 changed files with 780 additions and 1345 deletions
+39 -75
View File
@@ -5,7 +5,6 @@ import {
Get,
Post,
Param,
HttpException,
HttpStatus,
UseGuards,
Put,
@@ -36,24 +35,17 @@ export class ScheduleController {
@Param('deviceUuid') deviceUuid: string,
@Body() addScheduleDto: AddScheduleDto,
) {
try {
const schedule = await this.scheduleService.addDeviceSchedule(
deviceUuid,
addScheduleDto,
);
const schedule = await this.scheduleService.addDeviceSchedule(
deviceUuid,
addScheduleDto,
);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'schedule added successfully',
data: schedule,
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'schedule added successfully',
data: schedule,
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@@ -62,17 +54,10 @@ export class ScheduleController {
@Param('deviceUuid') deviceUuid: string,
@Query() query: GetScheduleDeviceDto,
) {
try {
return await this.scheduleService.getDeviceScheduleByCategory(
deviceUuid,
query.category,
);
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return await this.scheduleService.getDeviceScheduleByCategory(
deviceUuid,
query.category,
);
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@@ -81,19 +66,12 @@ export class ScheduleController {
@Param('deviceUuid') deviceUuid: string,
@Param('scheduleId') scheduleId: string,
) {
try {
await this.scheduleService.deleteDeviceSchedule(deviceUuid, scheduleId);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'schedule deleted successfully',
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
await this.scheduleService.deleteDeviceSchedule(deviceUuid, scheduleId);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'schedule deleted successfully',
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@@ -102,22 +80,15 @@ export class ScheduleController {
@Param('deviceUuid') deviceUuid: string,
@Body() enableScheduleDto: EnableScheduleDto,
) {
try {
await this.scheduleService.enableDeviceSchedule(
deviceUuid,
enableScheduleDto,
);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'schedule updated successfully',
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
await this.scheduleService.enableDeviceSchedule(
deviceUuid,
enableScheduleDto,
);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'schedule updated successfully',
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@@ -126,23 +97,16 @@ export class ScheduleController {
@Param('deviceUuid') deviceUuid: string,
@Body() updateScheduleDto: UpdateScheduleDto,
) {
try {
const schedule = await this.scheduleService.updateDeviceSchedule(
deviceUuid,
updateScheduleDto,
);
const schedule = await this.scheduleService.updateDeviceSchedule(
deviceUuid,
updateScheduleDto,
);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'schedule updated successfully',
data: schedule,
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'schedule updated successfully',
data: schedule,
};
}
}