mirror of
https://github.com/SyncrowIOT/backend.git
synced 2026-10-25 21:57:55 +00:00
Add endpoint to rename unit by UUID
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
HttpStatus,
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
Query,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
@@ -14,6 +15,7 @@ import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { JwtAuthGuard } from '../../../libs/common/src/guards/jwt.auth.guard';
|
||||
import { AddUnitDto } from '../dtos/add.unit.dto';
|
||||
import { GetUnitChildDto } from '../dtos/get.unit.dto';
|
||||
import { UpdateUnitNameDto } from '../dtos/update.unit.dto';
|
||||
|
||||
@ApiTags('Unit Module')
|
||||
@Controller({
|
||||
@@ -96,4 +98,29 @@ export class UnitController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Put('rename/:unitUuid')
|
||||
async renameUnitByUuid(
|
||||
@Param('unitUuid') unitUuid: string,
|
||||
@Body() updateUnitNameDto: UpdateUnitNameDto,
|
||||
) {
|
||||
try {
|
||||
const unit = await this.unitService.renameUnitByUuid(
|
||||
unitUuid,
|
||||
updateUnitNameDto,
|
||||
);
|
||||
return unit;
|
||||
} catch (error) {
|
||||
if (error.status === 404) {
|
||||
throw new HttpException('Unit not found', HttpStatus.NOT_FOUND);
|
||||
} else {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user