mirror of
https://github.com/SyncrowIOT/backend.git
synced 2026-10-24 07:17:55 +00:00
feat: Add unit invitation code functionality and user verification using code
This commit is contained in:
@@ -12,7 +12,11 @@ import {
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { AddUnitDto, AddUserUnitDto } from '../dtos/add.unit.dto';
|
||||
import {
|
||||
AddUnitDto,
|
||||
AddUserUnitDto,
|
||||
AddUserUnitUsingCodeDto,
|
||||
} from '../dtos/add.unit.dto';
|
||||
import { GetUnitChildDto } from '../dtos/get.unit.dto';
|
||||
import { UpdateUnitNameDto } from '../dtos/update.unit.dto';
|
||||
import { CheckFloorTypeGuard } from 'src/guards/floor.type.guard';
|
||||
@@ -30,7 +34,7 @@ export class UnitController {
|
||||
constructor(private readonly unitService: UnitService) {}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(AdminRoleGuard, CheckFloorTypeGuard)
|
||||
@UseGuards(JwtAuthGuard, CheckFloorTypeGuard)
|
||||
@Post()
|
||||
async addUnit(@Body() addUnitDto: AddUnitDto) {
|
||||
try {
|
||||
@@ -147,4 +151,39 @@ export class UnitController {
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard, UnitPermissionGuard)
|
||||
@Get(':unitUuid/invitation-code')
|
||||
async getUnitInvitationCode(@Param('unitUuid') unitUuid: string) {
|
||||
try {
|
||||
const unit = await this.unitService.getUnitInvitationCode(unitUuid);
|
||||
return unit;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('user/verify-code')
|
||||
async verifyCodeAndAddUserUnit(
|
||||
@Body() addUserUnitUsingCodeDto: AddUserUnitUsingCodeDto,
|
||||
) {
|
||||
try {
|
||||
await this.unitService.verifyCodeAndAddUserUnit(addUserUnitUsingCodeDto);
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'user unit added successfully',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user