You've already forked immich
mirror of
https://github.com/immich-app/immich.git
synced 2025-06-16 03:40:33 +02:00
refactor(server): auth route metadata (#9344)
This commit is contained in:
@ -19,7 +19,7 @@ import { NextFunction, Response } from 'express';
|
||||
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';
|
||||
import { AdminRoute, Auth, Authenticated, FileResponse } from 'src/middleware/auth.guard';
|
||||
import { Auth, Authenticated, FileResponse } from 'src/middleware/auth.guard';
|
||||
import { FileUploadInterceptor, Route } from 'src/middleware/file-upload.interceptor';
|
||||
import { UserService } from 'src/services/user.service';
|
||||
import { sendFile } from 'src/utils/file';
|
||||
@ -27,39 +27,42 @@ import { UUIDParamDto } from 'src/validation';
|
||||
|
||||
@ApiTags('User')
|
||||
@Controller(Route.USER)
|
||||
@Authenticated()
|
||||
export class UserController {
|
||||
constructor(private service: UserService) {}
|
||||
|
||||
@Get()
|
||||
@Authenticated()
|
||||
getAllUsers(@Auth() auth: AuthDto, @Query('isAll') isAll: boolean): Promise<UserResponseDto[]> {
|
||||
return this.service.getAll(auth, isAll);
|
||||
}
|
||||
|
||||
@Get('info/:id')
|
||||
@Authenticated()
|
||||
getUserById(@Param() { id }: UUIDParamDto): Promise<UserResponseDto> {
|
||||
return this.service.get(id);
|
||||
}
|
||||
|
||||
@Get('me')
|
||||
@Authenticated()
|
||||
getMyUserInfo(@Auth() auth: AuthDto): Promise<UserResponseDto> {
|
||||
return this.service.getMe(auth);
|
||||
}
|
||||
|
||||
@AdminRoute()
|
||||
@Post()
|
||||
@Authenticated({ admin: true })
|
||||
createUser(@Body() createUserDto: CreateUserDto): Promise<UserResponseDto> {
|
||||
return this.service.create(createUserDto);
|
||||
}
|
||||
|
||||
@Delete('profile-image')
|
||||
@HttpCode(HttpStatus.NO_CONTENT)
|
||||
@Authenticated()
|
||||
deleteProfileImage(@Auth() auth: AuthDto): Promise<void> {
|
||||
return this.service.deleteProfileImage(auth);
|
||||
}
|
||||
|
||||
@AdminRoute()
|
||||
@Delete(':id')
|
||||
@Authenticated({ admin: true })
|
||||
deleteUser(
|
||||
@Auth() auth: AuthDto,
|
||||
@Param() { id }: UUIDParamDto,
|
||||
@ -68,14 +71,15 @@ export class UserController {
|
||||
return this.service.delete(auth, id, dto);
|
||||
}
|
||||
|
||||
@AdminRoute()
|
||||
@Post(':id/restore')
|
||||
@Authenticated({ admin: true })
|
||||
restoreUser(@Auth() auth: AuthDto, @Param() { id }: UUIDParamDto): Promise<UserResponseDto> {
|
||||
return this.service.restore(auth, id);
|
||||
}
|
||||
|
||||
// TODO: replace with @Put(':id')
|
||||
@Put()
|
||||
@Authenticated()
|
||||
updateUser(@Auth() auth: AuthDto, @Body() updateUserDto: UpdateUserDto): Promise<UserResponseDto> {
|
||||
return this.service.update(auth, updateUserDto);
|
||||
}
|
||||
@ -84,6 +88,7 @@ export class UserController {
|
||||
@ApiConsumes('multipart/form-data')
|
||||
@ApiBody({ description: 'A new avatar for the user', type: CreateProfileImageDto })
|
||||
@Post('profile-image')
|
||||
@Authenticated()
|
||||
createProfileImage(
|
||||
@Auth() auth: AuthDto,
|
||||
@UploadedFile() fileInfo: Express.Multer.File,
|
||||
@ -93,6 +98,7 @@ export class UserController {
|
||||
|
||||
@Get('profile-image/:id')
|
||||
@FileResponse()
|
||||
@Authenticated()
|
||||
async getProfileImage(@Res() res: Response, @Next() next: NextFunction, @Param() { id }: UUIDParamDto) {
|
||||
await sendFile(res, next, () => this.service.getProfileImage(id));
|
||||
}
|
||||
|
Reference in New Issue
Block a user