HM-115. Добавлена ручка для получения информации о себе по токену, ручка по редактированию инфы о себе по токену

This commit is contained in:
vigdorov
2020-08-08 09:15:01 +03:00
parent f79e581dbf
commit 2c08d7d8c7
4 changed files with 57 additions and 6 deletions

View File

@ -14,6 +14,7 @@ import {
UserResponse,
CreateUserRequest,
UpdateUserRequest,
UpdateUserSelf,
} from './users.schema';
import { Request } from 'express';
import {
@ -48,7 +49,7 @@ export class UsersController {
return this.userService.findAll();
}
@Get(':login')
@Get('search/:login')
@Header(...ALLOW_ORIGIN_ALL)
@ApiResponse(FIND_ONE_SUCCESS)
@ApiResponse(FIND_ONE_NOT_FOUND)
@ -62,6 +63,22 @@ export class UsersController {
return await this.userService.findOne(request.params.login);
}
@Get('me')
@Header(...ALLOW_ORIGIN_ALL)
async findMe(@Req() request: Request): Promise<UserResponse> {
await this.authService.checkRequest(request);
return this.userService.findMe(request.headers.authorization);
}
@Post('edit-me')
@Header(...ALLOW_ORIGIN_ALL)
async findEdit(@Req() request: Request<null, UpdateUserSelf>): Promise<UserResponse> {
await this.authService.checkRequest(request);
return this.userService.updateSelf(request.headers.authorization, request.body);
}
@Post()
@Header(...ALLOW_ORIGIN_ALL)
@ApiResponse(CREATE_SUCCESS)
@ -107,7 +124,7 @@ export class UsersController {
}
@Options([
'', ':login'
'', 'search/:login', ':login', 'me', 'edit-me'
])
@Header(...ALLOW_ORIGIN_ALL)
@Header(...ALLOW_METHOD)