2022-05-28 05:24:58 +02:00
|
|
|
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, ValidationPipe, Put, Query, UseInterceptors, UploadedFile, Response } from '@nestjs/common';
|
2022-02-03 17:06:44 +01:00
|
|
|
import { UserService } from './user.service';
|
2022-04-24 04:08:45 +02:00
|
|
|
import { JwtAuthGuard } from '../../modules/immich-jwt/guards/jwt-auth.guard';
|
|
|
|
import { AuthUserDto, GetAuthUser } from '../../decorators/auth-user.decorator';
|
2022-05-21 09:23:55 +02:00
|
|
|
import { CreateUserDto } from './dto/create-user.dto';
|
|
|
|
import { AdminRolesGuard } from '../../middlewares/admin-role-guard.middleware';
|
|
|
|
import { UpdateUserDto } from './dto/update-user.dto';
|
2022-05-28 05:15:35 +02:00
|
|
|
import { FileInterceptor } from '@nestjs/platform-express';
|
|
|
|
import { profileImageUploadOption } from '../../config/profile-image-upload.config';
|
2022-05-28 05:24:58 +02:00
|
|
|
import { Response as Res } from 'express';
|
2022-02-03 17:06:44 +01:00
|
|
|
|
|
|
|
@Controller('user')
|
|
|
|
export class UserController {
|
2022-05-21 09:23:55 +02:00
|
|
|
constructor(private readonly userService: UserService) { }
|
2022-04-24 04:08:45 +02:00
|
|
|
|
2022-05-21 09:23:55 +02:00
|
|
|
@UseGuards(JwtAuthGuard)
|
2022-04-24 04:08:45 +02:00
|
|
|
@Get()
|
2022-05-21 09:23:55 +02:00
|
|
|
async getAllUsers(@GetAuthUser() authUser: AuthUserDto, @Query('isAll') isAll: boolean) {
|
|
|
|
return await this.userService.getAllUsers(authUser, isAll);
|
|
|
|
}
|
|
|
|
|
|
|
|
@UseGuards(JwtAuthGuard)
|
|
|
|
@UseGuards(AdminRolesGuard)
|
|
|
|
@Post()
|
|
|
|
async createNewUser(@Body(ValidationPipe) createUserDto: CreateUserDto) {
|
|
|
|
return await this.userService.createUser(createUserDto);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Get('/count')
|
|
|
|
async getUserCount(@Query('isAdmin') isAdmin: boolean) {
|
|
|
|
|
|
|
|
return await this.userService.getUserCount(isAdmin);
|
|
|
|
}
|
|
|
|
|
|
|
|
@UseGuards(JwtAuthGuard)
|
|
|
|
@Put()
|
|
|
|
async updateUser(@Body(ValidationPipe) updateUserDto: UpdateUserDto) {
|
|
|
|
return await this.userService.updateUser(updateUserDto)
|
2022-04-24 04:08:45 +02:00
|
|
|
}
|
2022-05-28 05:15:35 +02:00
|
|
|
|
|
|
|
@UseGuards(JwtAuthGuard)
|
|
|
|
@UseInterceptors(FileInterceptor('file', profileImageUploadOption))
|
|
|
|
@Post('/profile-image')
|
|
|
|
async createProfileImage(@GetAuthUser() authUser: AuthUserDto, @UploadedFile() fileInfo: Express.Multer.File) {
|
|
|
|
return await this.userService.createProfileImage(authUser, fileInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Get('/profile-image/:userId')
|
2022-05-28 05:24:58 +02:00
|
|
|
async getProfileImage(@Param('userId') userId: string,
|
|
|
|
@Response({ passthrough: true }) res: Res,
|
|
|
|
) {
|
|
|
|
return await this.userService.getUserProfileImage(userId, res);
|
2022-05-28 05:15:35 +02:00
|
|
|
}
|
2022-02-03 17:06:44 +01:00
|
|
|
}
|