feat: add user update
This commit is contained in:
parent
8f1d559210
commit
f6892a6a37
@ -4,7 +4,9 @@ import type {
|
|||||||
CreateUserRequest,
|
CreateUserRequest,
|
||||||
CreateUserResponse,
|
CreateUserResponse,
|
||||||
GetMeRequest,
|
GetMeRequest,
|
||||||
GetMeResponse
|
GetMeResponse,
|
||||||
|
PatchUserRequest,
|
||||||
|
PatchUserResponse
|
||||||
} from '@teacinema/contracts/gen/users'
|
} from '@teacinema/contracts/gen/users'
|
||||||
|
|
||||||
import { UsersService } from './users.service'
|
import { UsersService } from './users.service'
|
||||||
@ -22,4 +24,9 @@ export class UsersController {
|
|||||||
public async getMe(data: GetMeRequest): Promise<GetMeResponse> {
|
public async getMe(data: GetMeRequest): Promise<GetMeResponse> {
|
||||||
return this.usersService.getMe(data)
|
return this.usersService.getMe(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GrpcMethod('UsersService', 'PatchUser')
|
||||||
|
public async patch(data: PatchUserRequest): Promise<PatchUserResponse> {
|
||||||
|
return this.usersService.patchUser(data)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,7 @@ export class UsersRepository {
|
|||||||
private readonly repository: Repository<UserEntity>
|
private readonly repository: Repository<UserEntity>
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public findById(id: string) {
|
public findById(id: UserEntity['id']) {
|
||||||
return this.repository.findOne({ where: { id } })
|
return this.repository.findOne({ where: { id } })
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,4 +19,10 @@ export class UsersRepository {
|
|||||||
const user = this.repository.create(data)
|
const user = this.repository.create(data)
|
||||||
return this.repository.save(user)
|
return this.repository.save(user)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async update(id: UserEntity['id'], data: Partial<UserEntity>) {
|
||||||
|
await this.repository.update({ id }, data)
|
||||||
|
|
||||||
|
return this.findById(id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,9 @@ import { RpcStatus } from '@teacinema/common'
|
|||||||
import {
|
import {
|
||||||
CreateUserRequest,
|
CreateUserRequest,
|
||||||
GetMeRequest,
|
GetMeRequest,
|
||||||
GetMeResponse
|
GetMeResponse,
|
||||||
|
PatchUserRequest,
|
||||||
|
PatchUserResponse
|
||||||
} from '@teacinema/contracts/gen/users'
|
} from '@teacinema/contracts/gen/users'
|
||||||
import { lastValueFrom } from 'rxjs'
|
import { lastValueFrom } from 'rxjs'
|
||||||
|
|
||||||
@ -54,4 +56,25 @@ export class UsersService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async patchUser(data: PatchUserRequest): Promise<PatchUserResponse> {
|
||||||
|
const { name, userId } = data
|
||||||
|
|
||||||
|
const user = await this.repository.findById(userId)
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
throw new RpcException({
|
||||||
|
code: RpcStatus.NOT_FOUND,
|
||||||
|
details: 'User not found'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.repository.update(userId, {
|
||||||
|
...(name !== undefined && { name })
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
ok: true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
16
yarn.lock
16
yarn.lock
@ -1020,7 +1020,15 @@
|
|||||||
resolved "https://registry.yarnpkg.com/@nestjs/mapped-types/-/mapped-types-2.1.0.tgz#b9b536b7c3571567aa1d0223db8baa1a51505a19"
|
resolved "https://registry.yarnpkg.com/@nestjs/mapped-types/-/mapped-types-2.1.0.tgz#b9b536b7c3571567aa1d0223db8baa1a51505a19"
|
||||||
integrity sha512-W+n+rM69XsFdwORF11UqJahn4J3xi4g/ZEOlJNL6KoW5ygWSmBB2p0S2BZ4FQeS/NDH72e6xIcu35SfJnE8bXw==
|
integrity sha512-W+n+rM69XsFdwORF11UqJahn4J3xi4g/ZEOlJNL6KoW5ygWSmBB2p0S2BZ4FQeS/NDH72e6xIcu35SfJnE8bXw==
|
||||||
|
|
||||||
"@nestjs/microservices@^11.1.12", "@nestjs/microservices@^11.1.14":
|
"@nestjs/microservices@^11.1.12":
|
||||||
|
version "11.1.15"
|
||||||
|
resolved "https://registry.yarnpkg.com/@nestjs/microservices/-/microservices-11.1.15.tgz#e98d806d7bd813d0b0d3a1332fe70adb2b137623"
|
||||||
|
integrity sha512-9ee8AymMT/6HKNm10LRoYcUZKylu5K+FXRF7ynw+GlG4HXPVPlwst71wwNkbBHcqjJzfPhxEmC/j92sVeJURAg==
|
||||||
|
dependencies:
|
||||||
|
iterare "1.2.1"
|
||||||
|
tslib "2.8.1"
|
||||||
|
|
||||||
|
"@nestjs/microservices@^11.1.14":
|
||||||
version "11.1.14"
|
version "11.1.14"
|
||||||
resolved "https://registry.yarnpkg.com/@nestjs/microservices/-/microservices-11.1.14.tgz#8fa2de758ec2c768da7d993d79f772b699a507ff"
|
resolved "https://registry.yarnpkg.com/@nestjs/microservices/-/microservices-11.1.14.tgz#8fa2de758ec2c768da7d993d79f772b699a507ff"
|
||||||
integrity sha512-7x+QaX7351xJMYpjw4pqwoACXtSxuUQt4Prb7ZyqqsCawnBRrObPpZ/HIdpdKJPgo8vFfLJoAnkFJ+mQ6xz6Rw==
|
integrity sha512-7x+QaX7351xJMYpjw4pqwoACXtSxuUQt4Prb7ZyqqsCawnBRrObPpZ/HIdpdKJPgo8vFfLJoAnkFJ+mQ6xz6Rw==
|
||||||
@ -1174,9 +1182,9 @@
|
|||||||
integrity sha512-gMPQtWtlVQ5lEm4Z9eO/Iqd+5jyjsoHYR1HgD+JmkTai+Gj+Vz6UN4hNL2tso1mGIe6foNfYozbin2TEbBRzdg==
|
integrity sha512-gMPQtWtlVQ5lEm4Z9eO/Iqd+5jyjsoHYR1HgD+JmkTai+Gj+Vz6UN4hNL2tso1mGIe6foNfYozbin2TEbBRzdg==
|
||||||
|
|
||||||
"@teacinema/contracts@^1.1.2":
|
"@teacinema/contracts@^1.1.2":
|
||||||
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