2022-06-11 16:12:06 -05:00
|
|
|
import {
|
|
|
|
|
Controller,
|
|
|
|
|
Get,
|
|
|
|
|
Post,
|
|
|
|
|
Body,
|
|
|
|
|
Param,
|
|
|
|
|
ValidationPipe,
|
|
|
|
|
Put,
|
|
|
|
|
Query,
|
|
|
|
|
UseInterceptors,
|
|
|
|
|
UploadedFile,
|
|
|
|
|
Response,
|
2022-07-10 21:41:45 -05:00
|
|
|
ParseBoolPipe,
|
2022-06-11 16:12:06 -05:00
|
|
|
} from '@nestjs/common';
|
2022-02-03 10:06:44 -06:00
|
|
|
import { UserService } from './user.service';
|
2022-10-28 14:57:52 -04:00
|
|
|
import { Authenticated } from '../../decorators/authenticated.decorator';
|
2022-04-23 21:08:45 -05:00
|
|
|
import { AuthUserDto, GetAuthUser } from '../../decorators/auth-user.decorator';
|
2022-05-21 02:23:55 -05:00
|
|
|
import { CreateUserDto } from './dto/create-user.dto';
|
|
|
|
|
import { UpdateUserDto } from './dto/update-user.dto';
|
2022-05-27 22:15:35 -05:00
|
|
|
import { FileInterceptor } from '@nestjs/platform-express';
|
|
|
|
|
import { profileImageUploadOption } from '../../config/profile-image-upload.config';
|
2022-09-22 15:58:17 -05:00
|
|
|
import { Response as Res } from 'express';
|
2022-07-08 21:26:50 -05:00
|
|
|
import { ApiBearerAuth, ApiBody, ApiConsumes, ApiTags } from '@nestjs/swagger';
|
|
|
|
|
import { UserResponseDto } from './response-dto/user-response.dto';
|
|
|
|
|
import { UserCountResponseDto } from './response-dto/user-count-response.dto';
|
|
|
|
|
import { CreateProfileImageDto } from './dto/create-profile-image.dto';
|
|
|
|
|
import { CreateProfileImageResponseDto } from './response-dto/create-profile-image-response.dto';
|
2022-02-03 10:06:44 -06:00
|
|
|
|
2022-07-08 21:26:50 -05:00
|
|
|
@ApiTags('User')
|
2022-02-03 10:06:44 -06:00
|
|
|
@Controller('user')
|
|
|
|
|
export class UserController {
|
2022-06-11 16:12:06 -05:00
|
|
|
constructor(private readonly userService: UserService) {}
|
2022-04-23 21:08:45 -05:00
|
|
|
|
2022-10-28 14:57:52 -04:00
|
|
|
@Authenticated()
|
2022-07-08 21:26:50 -05:00
|
|
|
@ApiBearerAuth()
|
2022-04-23 21:08:45 -05:00
|
|
|
@Get()
|
2022-07-10 21:41:45 -05:00
|
|
|
async getAllUsers(
|
|
|
|
|
@GetAuthUser() authUser: AuthUserDto,
|
|
|
|
|
@Query('isAll', ParseBoolPipe) isAll: boolean,
|
|
|
|
|
): Promise<UserResponseDto[]> {
|
2022-05-21 02:23:55 -05:00
|
|
|
return await this.userService.getAllUsers(authUser, isAll);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-17 15:09:26 -05:00
|
|
|
@Get('/info/:userId')
|
2022-07-16 23:52:00 -05:00
|
|
|
async getUserById(@Param('userId') userId: string): Promise<UserResponseDto> {
|
|
|
|
|
return await this.userService.getUserById(userId);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-28 14:57:52 -04:00
|
|
|
@Authenticated()
|
2022-07-08 21:26:50 -05:00
|
|
|
@ApiBearerAuth()
|
2022-06-27 15:13:07 -05:00
|
|
|
@Get('me')
|
2022-07-08 21:26:50 -05:00
|
|
|
async getMyUserInfo(@GetAuthUser() authUser: AuthUserDto): Promise<UserResponseDto> {
|
2022-06-27 15:13:07 -05:00
|
|
|
return await this.userService.getUserInfo(authUser);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-28 14:57:52 -04:00
|
|
|
@Authenticated({ admin: true })
|
2022-07-08 21:26:50 -05:00
|
|
|
@ApiBearerAuth()
|
2022-05-21 02:23:55 -05:00
|
|
|
@Post()
|
2022-08-15 19:11:08 -05:00
|
|
|
async createUser(
|
|
|
|
|
@Body(new ValidationPipe({ transform: true })) createUserDto: CreateUserDto,
|
|
|
|
|
): Promise<UserResponseDto> {
|
2022-05-21 02:23:55 -05:00
|
|
|
return await this.userService.createUser(createUserDto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get('/count')
|
2022-07-10 21:41:45 -05:00
|
|
|
async getUserCount(): Promise<UserCountResponseDto> {
|
|
|
|
|
return await this.userService.getUserCount();
|
2022-05-21 02:23:55 -05:00
|
|
|
}
|
|
|
|
|
|
2022-10-28 14:57:52 -04:00
|
|
|
@Authenticated()
|
2022-07-08 21:26:50 -05:00
|
|
|
@ApiBearerAuth()
|
2022-05-21 02:23:55 -05:00
|
|
|
@Put()
|
2022-09-18 09:27:06 -05:00
|
|
|
async updateUser(
|
|
|
|
|
@GetAuthUser() authUser: AuthUserDto,
|
|
|
|
|
@Body(ValidationPipe) updateUserDto: UpdateUserDto,
|
|
|
|
|
): Promise<UserResponseDto> {
|
|
|
|
|
return await this.userService.updateUser(authUser, updateUserDto);
|
2022-04-23 21:08:45 -05:00
|
|
|
}
|
2022-05-27 22:15:35 -05:00
|
|
|
|
|
|
|
|
@UseInterceptors(FileInterceptor('file', profileImageUploadOption))
|
2022-10-28 14:57:52 -04:00
|
|
|
@Authenticated()
|
2022-07-08 21:26:50 -05:00
|
|
|
@ApiBearerAuth()
|
|
|
|
|
@ApiConsumes('multipart/form-data')
|
|
|
|
|
@ApiBody({
|
2022-07-13 07:23:48 -05:00
|
|
|
description: 'A new avatar for the user',
|
2022-07-08 21:26:50 -05:00
|
|
|
type: CreateProfileImageDto,
|
|
|
|
|
})
|
2022-05-27 22:15:35 -05:00
|
|
|
@Post('/profile-image')
|
2022-07-08 21:26:50 -05:00
|
|
|
async createProfileImage(
|
|
|
|
|
@GetAuthUser() authUser: AuthUserDto,
|
|
|
|
|
@UploadedFile() fileInfo: Express.Multer.File,
|
|
|
|
|
): Promise<CreateProfileImageResponseDto> {
|
2022-05-27 22:15:35 -05:00
|
|
|
return await this.userService.createProfileImage(authUser, fileInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get('/profile-image/:userId')
|
2022-07-10 21:41:45 -05:00
|
|
|
async getProfileImage(@Param('userId') userId: string, @Response({ passthrough: true }) res: Res): Promise<any> {
|
2022-07-08 21:26:50 -05:00
|
|
|
return this.userService.getUserProfileImage(userId, res);
|
2022-05-27 22:15:35 -05:00
|
|
|
}
|
2022-02-03 10:06:44 -06:00
|
|
|
}
|