finished update schedule endpoint

This commit is contained in:
faris Aljohari
2024-10-01 17:16:50 -05:00
parent e69b5a44d7
commit c387c5984d
3 changed files with 148 additions and 3 deletions
@@ -17,6 +17,7 @@ import {
AddScheduleDto,
EnableScheduleDto,
GetScheduleDeviceDto,
UpdateScheduleDto,
} from '../dtos/schedule.dto';
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
@@ -36,7 +37,7 @@ export class ScheduleController {
@Body() addScheduleDto: AddScheduleDto,
) {
try {
const device = await this.scheduleService.addDeviceSchedule(
const schedule = await this.scheduleService.addDeviceSchedule(
deviceUuid,
addScheduleDto,
);
@@ -45,7 +46,7 @@ export class ScheduleController {
statusCode: HttpStatus.CREATED,
success: true,
message: 'schedule added successfully',
data: device,
data: schedule,
};
} catch (error) {
throw new HttpException(
@@ -118,4 +119,30 @@ export class ScheduleController {
);
}
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Put(':deviceUuid')
async updateDeviceSchedule(
@Param('deviceUuid') deviceUuid: string,
@Body() updateScheduleDto: UpdateScheduleDto,
) {
try {
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,
);
}
}
}