on auth token for users

This commit is contained in:
vigdorov
2020-08-04 22:44:05 +03:00
parent 9372605535
commit f79e581dbf
3 changed files with 39 additions and 3 deletions

View File

@ -29,18 +29,22 @@ import {
REMOVE_SUCCESS,
REMOVE_NOT_FOUND,
} from './users.responses';
import {AuthService} from 'src/auth/auth.service';
@Controller(USERS_CONTROLLER)
@ApiTags(USERS_CONTROLLER)
export class UsersController {
constructor(
private readonly userService: UserService
private readonly userService: UserService,
private readonly authService: AuthService,
) {}
@Get()
@Header(...ALLOW_ORIGIN_ALL)
@ApiResponse(FIND_ALL_SUCCESS)
async findAll(): Promise<UserResponse[]> {
async findAll(@Req() request: Request): Promise<UserResponse[]> {
await this.authService.checkRequest(request);
return this.userService.findAll();
}
@ -53,6 +57,8 @@ export class UsersController {
description: 'Логин пользователя',
})
async findOne(@Req() request: Request<{login: string}>): Promise<UserResponse> {
await this.authService.checkRequest(request);
return await this.userService.findOne(request.params.login);
}
@ -66,6 +72,8 @@ export class UsersController {
description: 'Объект для создания пользователя'
})
async createUser(@Req() request: Request<null, CreateUserRequest>): Promise<UserResponse> {
await this.authService.checkRequest(request);
return await this.userService.create(request.body);
}
@ -79,6 +87,8 @@ export class UsersController {
description: 'Объект обновления данных пользователя'
})
async updateUser(@Req() request: Request<null, UpdateUserRequest>): Promise<UserResponse> {
await this.authService.checkRequest(request);
return await this.userService.update(request.body);
}
@ -91,6 +101,8 @@ export class UsersController {
description: 'Логин пользователя',
})
async removeUser(@Req() request: Request<{login: string}>): Promise<UpdateUserRequest> {
await this.authService.checkRequest(request);
return await this.userService.removeOne(request.params.login);
}