Skip to content

Commit f599258

Browse files
committed
feat: entity 및 dto 생성
1 parent af077f5 commit f599258

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

apps/backend/src/auth/auth.service.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { Injectable } from '@nestjs/common';
22
import { UserRepository } from '../user/user.repository';
33
import { User } from '../user/user.entity';
44
import { SignUpDto } from './dtos/signUp.dto';
5+
import { UpdateUserDto } from './dtos/UpdateUser.dto';
6+
import { UserNotFoundException } from 'src/exception/user.exception';
57

68
@Injectable()
79
export 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
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
}

apps/backend/src/user/user.entity.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)