mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-27 02:54:54 +00:00
65 lines
1.8 KiB
TypeScript
65 lines
1.8 KiB
TypeScript
import { ControllerRoute } from '@app/common/constants/controller-route';
|
|
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
|
import {
|
|
Body,
|
|
Controller,
|
|
Get,
|
|
HttpException,
|
|
HttpStatus,
|
|
Param,
|
|
Post,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
|
import { UserSpaceService } from '../services';
|
|
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
|
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
|
import { AddUserSpaceUsingCodeDto, UserParamDto } from '../dtos';
|
|
|
|
@ApiTags('User Module')
|
|
@Controller({
|
|
version: EnableDisableStatusEnum.ENABLED,
|
|
path: ControllerRoute.USER_SPACE.ROUTE,
|
|
})
|
|
export class UserSpaceController {
|
|
constructor(private readonly userSpaceService: UserSpaceService) {}
|
|
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard)
|
|
@Get()
|
|
@ApiOperation({
|
|
summary: ControllerRoute.USER_SPACE.ACTIONS.GET_USER_SPACES_SUMMARY,
|
|
description: ControllerRoute.USER_SPACE.ACTIONS.GET_USER_SPACES_DESCRIPTION,
|
|
})
|
|
async getSpacesForUser(
|
|
@Param() params: UserParamDto,
|
|
): Promise<BaseResponseDto> {
|
|
return this.userSpaceService.getSpacesForUser(params.userUuid);
|
|
}
|
|
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard)
|
|
@Post('/verify-code')
|
|
async verifyCodeAndAddUserSpace(
|
|
@Body() dto: AddUserSpaceUsingCodeDto,
|
|
@Param() params: UserParamDto,
|
|
) {
|
|
try {
|
|
await this.userSpaceService.verifyCodeAndAddUserSpace(
|
|
dto,
|
|
params.userUuid,
|
|
);
|
|
return {
|
|
statusCode: HttpStatus.CREATED,
|
|
success: true,
|
|
message: 'user space added successfully',
|
|
};
|
|
} catch (error) {
|
|
throw new HttpException(
|
|
error.message || 'Internal server error',
|
|
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
|
);
|
|
}
|
|
}
|
|
}
|