mirror of
https://github.com/SyncrowIOT/backend.git
synced 2026-10-25 07:37:56 +00:00
feat: add user profile picture, region, and timezone update functionality
This commit is contained in:
@@ -1,8 +1,22 @@
|
||||
import { Controller, Get, Query, UseGuards } from '@nestjs/common';
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Param,
|
||||
Put,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { UserService } from '../services/user.service';
|
||||
import { UserListDto } from '../dtos/user.list.dto';
|
||||
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { AdminRoleGuard } from 'src/guards/admin.role.guard';
|
||||
import { JwtAuthGuard } from '../../../libs/common/src/guards/jwt.auth.guard';
|
||||
import {
|
||||
UpdateProfilePictureDataDto,
|
||||
UpdateRegionDataDto,
|
||||
UpdateTimezoneDataDto,
|
||||
} from '../dtos';
|
||||
import { CheckProfilePictureGuard } from 'src/guards/profile.picture.guard';
|
||||
|
||||
@ApiTags('User Module')
|
||||
@Controller({
|
||||
@@ -13,13 +27,91 @@ export class UserController {
|
||||
constructor(private readonly userService: UserService) {}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(AdminRoleGuard)
|
||||
@Get('list')
|
||||
async userList(@Query() userListDto: UserListDto) {
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get(':userUuid')
|
||||
async getUserDetailsByUserUuid(@Param('userUuid') userUuid: string) {
|
||||
try {
|
||||
return await this.userService.userDetails(userListDto);
|
||||
} catch (err) {
|
||||
throw new Error(err);
|
||||
return await this.userService.getUserDetailsByUserUuid(userUuid);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard, CheckProfilePictureGuard)
|
||||
@Put('/profile-picture/:userUuid')
|
||||
async updateProfilePictureByUserUuid(
|
||||
@Param('userUuid') userUuid: string,
|
||||
@Body() updateProfilePictureDataDto: UpdateProfilePictureDataDto,
|
||||
) {
|
||||
try {
|
||||
const userData = await this.userService.updateProfilePictureByUserUuid(
|
||||
userUuid,
|
||||
updateProfilePictureDataDto,
|
||||
);
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'profile picture updated successfully',
|
||||
data: userData,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Put('/region/:userUuid')
|
||||
async updateRegionByUserUuid(
|
||||
@Param('userUuid') userUuid: string,
|
||||
@Body() updateRegionDataDto: UpdateRegionDataDto,
|
||||
) {
|
||||
try {
|
||||
const userData = await this.userService.updateRegionByUserUuid(
|
||||
userUuid,
|
||||
updateRegionDataDto,
|
||||
);
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'region updated successfully',
|
||||
data: userData,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Put('/timezone/:userUuid')
|
||||
async updateTimezoneByUserUuid(
|
||||
@Param('userUuid') userUuid: string,
|
||||
@Body() updateTimezoneDataDto: UpdateTimezoneDataDto,
|
||||
) {
|
||||
try {
|
||||
const userData = await this.userService.updateTimezoneByUserUuid(
|
||||
userUuid,
|
||||
updateTimezoneDataDto,
|
||||
);
|
||||
return {
|
||||
statusCode: HttpStatus.CREATED,
|
||||
success: true,
|
||||
message: 'timezone updated successfully',
|
||||
data: userData,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user