2023-06-16 21:54:17 +02:00
|
|
|
import {
|
|
|
|
Body,
|
2022-06-11 23:12:06 +02:00
|
|
|
Controller,
|
2022-11-07 22:53:47 +01:00
|
|
|
Delete,
|
2023-06-16 21:54:17 +02:00
|
|
|
Get,
|
2023-11-14 04:10:35 +01:00
|
|
|
HttpCode,
|
|
|
|
HttpStatus,
|
2023-12-18 17:33:46 +01:00
|
|
|
Next,
|
2022-06-11 23:12:06 +02:00
|
|
|
Param,
|
2023-06-16 21:54:17 +02:00
|
|
|
Post,
|
2022-06-11 23:12:06 +02:00
|
|
|
Put,
|
|
|
|
Query,
|
2023-12-18 17:33:46 +01:00
|
|
|
Res,
|
2023-06-16 21:54:17 +02:00
|
|
|
UploadedFile,
|
|
|
|
UseInterceptors,
|
2022-06-11 23:12:06 +02:00
|
|
|
} from '@nestjs/common';
|
2023-02-24 17:01:10 +01:00
|
|
|
import { ApiBody, ApiConsumes, ApiTags } from '@nestjs/swagger';
|
2023-12-18 17:33:46 +01:00
|
|
|
import { NextFunction, Response } from 'express';
|
2024-03-20 19:32:04 +01:00
|
|
|
import { UserService } from 'src/domain/user/user.service';
|
2024-03-20 23:53:07 +01:00
|
|
|
import { AuthDto } from 'src/dtos/auth.dto';
|
|
|
|
import { CreateProfileImageDto, CreateProfileImageResponseDto } from 'src/dtos/user-profile.dto';
|
|
|
|
import { CreateUserDto, DeleteUserDto, UpdateUserDto, UserResponseDto } from 'src/dtos/user.dto';
|
2024-03-20 19:32:04 +01:00
|
|
|
import { sendFile } from 'src/immich/app.utils';
|
2024-03-20 21:15:01 +01:00
|
|
|
import { AdminRoute, Auth, Authenticated, FileResponse } from 'src/middleware/auth.guard';
|
|
|
|
import { FileUploadInterceptor, Route } from 'src/middleware/file-upload.interceptor';
|
2024-03-20 21:04:03 +01:00
|
|
|
import { UUIDParamDto } from 'src/validation';
|
2022-02-03 17:06:44 +01:00
|
|
|
|
2022-07-09 04:26:50 +02:00
|
|
|
@ApiTags('User')
|
2023-07-09 06:37:40 +02:00
|
|
|
@Controller(Route.USER)
|
2023-05-28 18:30:01 +02:00
|
|
|
@Authenticated()
|
2022-02-03 17:06:44 +01:00
|
|
|
export class UserController {
|
2023-03-24 05:53:56 +01:00
|
|
|
constructor(private service: UserService) {}
|
2022-04-24 04:08:45 +02:00
|
|
|
|
|
|
|
@Get()
|
2023-12-10 05:34:12 +01:00
|
|
|
getAllUsers(@Auth() auth: AuthDto, @Query('isAll') isAll: boolean): Promise<UserResponseDto[]> {
|
|
|
|
return this.service.getAll(auth, isAll);
|
2022-05-21 09:23:55 +02:00
|
|
|
}
|
|
|
|
|
2023-08-03 20:17:38 +02:00
|
|
|
@Get('info/:id')
|
|
|
|
getUserById(@Param() { id }: UUIDParamDto): Promise<UserResponseDto> {
|
|
|
|
return this.service.get(id);
|
2022-07-17 06:52:00 +02:00
|
|
|
}
|
|
|
|
|
2022-06-27 22:13:07 +02:00
|
|
|
@Get('me')
|
2023-12-10 05:34:12 +01:00
|
|
|
getMyUserInfo(@Auth() auth: AuthDto): Promise<UserResponseDto> {
|
|
|
|
return this.service.getMe(auth);
|
2022-06-27 22:13:07 +02:00
|
|
|
}
|
|
|
|
|
2023-05-28 18:30:01 +02:00
|
|
|
@AdminRoute()
|
2022-05-21 09:23:55 +02:00
|
|
|
@Post()
|
2024-03-20 19:32:04 +01:00
|
|
|
createUser(@Body() createUserDto: CreateUserDto): Promise<UserResponseDto> {
|
2023-08-03 20:17:38 +02:00
|
|
|
return this.service.create(createUserDto);
|
2022-05-21 09:23:55 +02:00
|
|
|
}
|
|
|
|
|
2023-11-14 04:10:35 +01:00
|
|
|
@Delete('profile-image')
|
|
|
|
@HttpCode(HttpStatus.NO_CONTENT)
|
2023-12-10 05:34:12 +01:00
|
|
|
deleteProfileImage(@Auth() auth: AuthDto): Promise<void> {
|
|
|
|
return this.service.deleteProfileImage(auth);
|
2023-11-14 04:10:35 +01:00
|
|
|
}
|
|
|
|
|
2023-05-28 18:30:01 +02:00
|
|
|
@AdminRoute()
|
2023-08-03 20:17:38 +02:00
|
|
|
@Delete(':id')
|
2024-03-08 23:49:39 +01:00
|
|
|
deleteUser(
|
|
|
|
@Auth() auth: AuthDto,
|
|
|
|
@Param() { id }: UUIDParamDto,
|
|
|
|
@Body() dto: DeleteUserDto,
|
|
|
|
): Promise<UserResponseDto> {
|
|
|
|
return this.service.delete(auth, id, dto);
|
2022-11-07 22:53:47 +01:00
|
|
|
}
|
|
|
|
|
2023-05-28 18:30:01 +02:00
|
|
|
@AdminRoute()
|
2023-08-03 20:17:38 +02:00
|
|
|
@Post(':id/restore')
|
2023-12-10 05:34:12 +01:00
|
|
|
restoreUser(@Auth() auth: AuthDto, @Param() { id }: UUIDParamDto): Promise<UserResponseDto> {
|
|
|
|
return this.service.restore(auth, id);
|
2022-11-07 22:53:47 +01:00
|
|
|
}
|
|
|
|
|
2023-08-01 17:49:50 +02:00
|
|
|
// TODO: replace with @Put(':id')
|
2022-05-21 09:23:55 +02:00
|
|
|
@Put()
|
2024-03-20 19:32:04 +01:00
|
|
|
updateUser(@Auth() auth: AuthDto, @Body() updateUserDto: UpdateUserDto): Promise<UserResponseDto> {
|
2023-12-10 05:34:12 +01:00
|
|
|
return this.service.update(auth, updateUserDto);
|
2022-04-24 04:08:45 +02:00
|
|
|
}
|
2022-05-28 05:15:35 +02:00
|
|
|
|
2023-07-09 06:37:40 +02:00
|
|
|
@UseInterceptors(FileUploadInterceptor)
|
2022-07-09 04:26:50 +02:00
|
|
|
@ApiConsumes('multipart/form-data')
|
2023-07-09 06:37:40 +02:00
|
|
|
@ApiBody({ description: 'A new avatar for the user', type: CreateProfileImageDto })
|
2023-08-03 20:17:38 +02:00
|
|
|
@Post('profile-image')
|
2023-03-24 05:53:56 +01:00
|
|
|
createProfileImage(
|
2023-12-10 05:34:12 +01:00
|
|
|
@Auth() auth: AuthDto,
|
2022-07-09 04:26:50 +02:00
|
|
|
@UploadedFile() fileInfo: Express.Multer.File,
|
|
|
|
): Promise<CreateProfileImageResponseDto> {
|
2023-12-10 05:34:12 +01:00
|
|
|
return this.service.createProfileImage(auth, fileInfo);
|
2022-05-28 05:15:35 +02:00
|
|
|
}
|
|
|
|
|
2023-08-03 20:17:38 +02:00
|
|
|
@Get('profile-image/:id')
|
2023-12-12 15:58:25 +01:00
|
|
|
@FileResponse()
|
2023-12-18 17:33:46 +01:00
|
|
|
async getProfileImage(@Res() res: Response, @Next() next: NextFunction, @Param() { id }: UUIDParamDto) {
|
|
|
|
await sendFile(res, next, () => this.service.getProfileImage(id));
|
2022-05-28 05:15:35 +02:00
|
|
|
}
|
2022-02-03 17:06:44 +01:00
|
|
|
}
|