feat: add user update
This commit is contained in:
parent
03d4f38fb0
commit
a85af3eb0c
@ -1 +1,2 @@
|
|||||||
export * from './rs'
|
export * from './rs'
|
||||||
|
export * from './rq'
|
||||||
|
|||||||
1
src/modules/users/dto/rq/index.ts
Normal file
1
src/modules/users/dto/rq/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './patch-user.request.dto'
|
||||||
9
src/modules/users/dto/rq/patch-user.request.dto.ts
Normal file
9
src/modules/users/dto/rq/patch-user.request.dto.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { ApiProperty } from '@nestjs/swagger'
|
||||||
|
import { IsNotEmpty, IsString } from 'class-validator'
|
||||||
|
|
||||||
|
export class PatchUserRequestDto {
|
||||||
|
@ApiProperty({ example: 'Ivan' })
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
public name: string
|
||||||
|
}
|
||||||
@ -1 +1,2 @@
|
|||||||
export * from './get-me.response.dto'
|
export * from './get-me.response.dto'
|
||||||
|
export * from './patch-user.response.dto'
|
||||||
|
|||||||
6
src/modules/users/dto/rs/patch-user.response.dto.ts
Normal file
6
src/modules/users/dto/rs/patch-user.response.dto.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import { ApiProperty } from '@nestjs/swagger'
|
||||||
|
|
||||||
|
export class PatchUserResponseDto {
|
||||||
|
@ApiProperty({ example: 'true' })
|
||||||
|
public ok: boolean
|
||||||
|
}
|
||||||
@ -1,10 +1,21 @@
|
|||||||
import { Controller, Get, HttpCode, HttpStatus } from '@nestjs/common'
|
import {
|
||||||
|
Body,
|
||||||
|
Controller,
|
||||||
|
Get,
|
||||||
|
HttpCode,
|
||||||
|
HttpStatus,
|
||||||
|
Patch
|
||||||
|
} from '@nestjs/common'
|
||||||
import { ApiBearerAuth, ApiOkResponse, ApiOperation } from '@nestjs/swagger'
|
import { ApiBearerAuth, ApiOkResponse, ApiOperation } from '@nestjs/swagger'
|
||||||
import { lastValueFrom } from 'rxjs'
|
import { lastValueFrom } from 'rxjs'
|
||||||
|
|
||||||
import { CurrentUser, Protected } from '../../shared/decorators'
|
import { CurrentUser, Protected } from '../../shared/decorators'
|
||||||
|
|
||||||
import { GetMeResponseDto } from './dto'
|
import {
|
||||||
|
GetMeResponseDto,
|
||||||
|
PatchUserRequestDto,
|
||||||
|
PatchUserResponseDto
|
||||||
|
} from './dto'
|
||||||
import { UsersClientGrpc } from './users.grpc'
|
import { UsersClientGrpc } from './users.grpc'
|
||||||
|
|
||||||
@Controller('users')
|
@Controller('users')
|
||||||
@ -24,4 +35,20 @@ export class UsersController {
|
|||||||
const { user } = await lastValueFrom(this.client.getMe({ id: userId }))
|
const { user } = await lastValueFrom(this.client.getMe({ id: userId }))
|
||||||
return user
|
return user
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation({
|
||||||
|
summary: 'Update user',
|
||||||
|
description: 'Update user info'
|
||||||
|
})
|
||||||
|
@ApiBearerAuth()
|
||||||
|
@ApiOkResponse({ type: PatchUserResponseDto })
|
||||||
|
@Protected()
|
||||||
|
@Patch('me')
|
||||||
|
@HttpCode(HttpStatus.OK)
|
||||||
|
public patchUser(
|
||||||
|
@CurrentUser() userId: string,
|
||||||
|
@Body() dto: PatchUserRequestDto
|
||||||
|
) {
|
||||||
|
return this.client.patchUser({ userId, ...dto })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import { Inject, Injectable, OnModuleInit } from '@nestjs/common'
|
|||||||
import type { ClientGrpc } from '@nestjs/microservices'
|
import type { ClientGrpc } from '@nestjs/microservices'
|
||||||
import {
|
import {
|
||||||
GetMeRequest,
|
GetMeRequest,
|
||||||
|
PatchUserRequest,
|
||||||
UsersServiceClient
|
UsersServiceClient
|
||||||
} from '@teacinema/contracts/gen/users'
|
} from '@teacinema/contracts/gen/users'
|
||||||
|
|
||||||
@ -19,4 +20,8 @@ export class UsersClientGrpc implements OnModuleInit {
|
|||||||
public getMe(request: GetMeRequest) {
|
public getMe(request: GetMeRequest) {
|
||||||
return this.usersService.getMe(request)
|
return this.usersService.getMe(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public patchUser(request: PatchUserRequest) {
|
||||||
|
return this.usersService.patchUser(request)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
12
yarn.lock
12
yarn.lock
@ -1216,14 +1216,14 @@
|
|||||||
"@sinonjs/commons" "^3.0.1"
|
"@sinonjs/commons" "^3.0.1"
|
||||||
|
|
||||||
"@teacinema/common@^1.0.0":
|
"@teacinema/common@^1.0.0":
|
||||||
version "1.0.1"
|
version "1.0.2"
|
||||||
resolved "https://git.ksv741.keenetic.pro/api/packages/teacinema/npm/%40teacinema%2Fcommon/-/1.0.1/common-1.0.1.tgz#40ad9ced1522b53fa6e46d7f6797cc03193705ab"
|
resolved "https://git.ksv741.keenetic.pro/api/packages/teacinema/npm/%40teacinema%2Fcommon/-/1.0.2/common-1.0.2.tgz#72b98bc641042e8c6a42c2285bfd49d84ea6a195"
|
||||||
integrity sha512-q3DURJbSk3k8MNWFIYaSM4LEcBgPbWa+HJmBz/nzYT4kuYitJVSXxpZ97kr0Ea+81AZwAU3JhQKlkK0SBWUi0A==
|
integrity sha512-gMPQtWtlVQ5lEm4Z9eO/Iqd+5jyjsoHYR1HgD+JmkTai+Gj+Vz6UN4hNL2tso1mGIe6foNfYozbin2TEbBRzdg==
|
||||||
|
|
||||||
"@teacinema/contracts@^1.0.0":
|
"@teacinema/contracts@^1.0.0":
|
||||||
version "1.1.2"
|
version "1.1.3"
|
||||||
resolved "https://git.ksv741.keenetic.pro/api/packages/teacinema/npm/%40teacinema%2Fcontracts/-/1.1.2/contracts-1.1.2.tgz#74e5ce7c95515983fd299332ef095a882dbe6665"
|
resolved "https://git.ksv741.keenetic.pro/api/packages/teacinema/npm/%40teacinema%2Fcontracts/-/1.1.3/contracts-1.1.3.tgz#e08600a8dc09977dae35654d372e29e411029e33"
|
||||||
integrity sha512-LL9UqmjIX0C9kHVtyoAoNUrp0zk1u/JzNTfnU+gqTXHJhejHOSa3blVtQBO4cjTt+yYDaN89fjm5fRbL/V0dDw==
|
integrity sha512-kwcSh2YIxmoBJQ56L+tQpGj12ySwNwf9KRNcUqhPffLPO60PR5aiKA2eN2SfKc23TKp0YoSkdC9LWeor0a9Ysg==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@nestjs/microservices" "^11.1.12"
|
"@nestjs/microservices" "^11.1.12"
|
||||||
protoc "33.4.0"
|
protoc "33.4.0"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user