File tree Expand file tree Collapse file tree 3 files changed +55
-0
lines changed
Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ import { Injectable } from '@nestjs/common';
22import { UserRepository } from '../user/user.repository' ;
33import { User } from '../user/user.entity' ;
44import { SignUpDto } from './dtos/signUp.dto' ;
5+ import { UpdateUserDto } from './dtos/UpdateUser.dto' ;
6+ import { UserNotFoundException } from 'src/exception/user.exception' ;
57
68@Injectable ( )
79export class AuthService {
@@ -25,4 +27,19 @@ export class AuthService {
2527 async findUserById ( id : number ) : Promise < User | null > {
2628 return await this . userRepository . findOneBy ( { id } ) ;
2729 }
30+ async updateUser ( dto : UpdateUserDto ) {
31+ // 유저를 찾는다.
32+ const findUser = await this . userRepository . findBy ( {
33+ snowflakeId : dto . snowflakeId ,
34+ } ) ;
35+
36+ // 유저가 없으면 오류
37+ if ( ! findUser ) {
38+ throw new UserNotFoundException ( ) ;
39+ }
40+
41+ // 유저 갱신
42+ const newPage = Object . assign ( { } , findUser , dto ) ;
43+ await this . userRepository . save ( newPage ) ;
44+ }
2845}
Original file line number Diff line number Diff line change 1+ import { ApiProperty } from '@nestjs/swagger' ;
2+ import {
3+ IsString ,
4+ IsNumber ,
5+ IsJSON ,
6+ IsOptional ,
7+ IsNotEmpty ,
8+ } from 'class-validator' ;
9+
10+ export class UpdateUserDto {
11+ @ApiProperty ( {
12+ example : 'abc123' ,
13+ description : 'user의 snowflake id' ,
14+ } )
15+ @IsString ( )
16+ snowflakeId : string ;
17+
18+ @ApiProperty ( {
19+ example : '#FF8A8A' ,
20+ description : '유저의 커서 색상' ,
21+ } )
22+ @IsString ( )
23+ @IsOptional ( )
24+ cursorColor ?: string ;
25+
26+ @ApiProperty ( {
27+ example : '#FF8A8A' ,
28+ description : '유저의 커서 색상' ,
29+ } )
30+ @IsString ( )
31+ @IsOptional ( )
32+ nickname ?: string ;
33+ }
Original file line number Diff line number Diff line change @@ -26,6 +26,11 @@ export class User {
2626 @Column ( )
2727 email : string ;
2828
29+ @Column ( {
30+ default : '#FF8A8A' ,
31+ } )
32+ cursorColor : string ;
33+
2934 @Column ( { nullable : true } )
3035 nickname : string ;
3136
You can’t perform that action at this time.
0 commit comments