Skip to content

Commit d0194be

Browse files
committed
refactor/#108: adjust types and configurations
1 parent 4a6803d commit d0194be

File tree

4 files changed

+28
-35
lines changed

4 files changed

+28
-35
lines changed

src/apis/auth/social/dto/auth-social.dto.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ApiProperty } from "@nestjs/swagger";
22
import { UserGender, UserLoginType, UserRole } from "@src/apis/users/constants/user.enum";
33
import { PHONE_NUMBER_REGEXP } from "@src/constants/regexp.constant";
44
import { IsNullable } from "@src/decorators/validators/is-nullable.decorator";
5-
import { IsEmail, IsEnum, IsOptional, IsString, Length, Matches, Max, Min } from "class-validator";
5+
import { IsEmail, IsEnum, IsInt, IsString, Length, Matches, Max, Min } from "class-validator";
66
import { CheckRegistrationRequestBodyDto } from "./auth-registration.dto";
77
import { USER_GRADE, USER_NAME_LENGTH } from "@src/apis/users/constants/user.constant";
88

@@ -13,21 +13,24 @@ export class SignUpRequestBodyDto extends CheckRegistrationRequestBodyDto {
1313
maxLength: USER_NAME_LENGTH.MAX,
1414
})
1515
@Length(USER_NAME_LENGTH.MIN, USER_NAME_LENGTH.MAX)
16+
@IsNullable()
1617
name: string;
1718

1819
@ApiProperty({
1920
description: 'email',
2021
format: 'email',
2122
})
2223
@IsEmail()
24+
@IsNullable()
2325
email: string;
2426

2527
@ApiProperty({
2628
description: 'role',
2729
enum: UserRole,
2830
})
2931
@IsEnum(UserRole)
30-
role: UserRole;
32+
@IsNullable()
33+
role: UserRole = UserRole.Student;
3134

3235
@ApiProperty({
3336
description: 'phone number',
@@ -71,8 +74,9 @@ export class SignUpRequestBodyDto extends CheckRegistrationRequestBodyDto {
7174
@IsNullable()
7275
profilePath: string | null;
7376

74-
@IsOptional()
75-
majorId: number = 1;
77+
@IsInt()
78+
@IsNullable()
79+
majorId: number;
7680
}
7781

7882
export class SignInRequestBodyDto extends CheckRegistrationRequestBodyDto { }

src/apis/auth/social/service/auth-social.service.ts

+18-29
Original file line numberDiff line numberDiff line change
@@ -9,53 +9,42 @@ import { HttpInternalServerErrorException } from "@src/http-exceptions/exception
99
import { COMMON_ERROR_CODE } from "@src/constants/error/common/common-error-code.constant";
1010
import { AUTH_ERROR_CODE } from "@src/constants/error/auth/auth-error-code.constant";
1111
import { AuthService } from "../../services/auth.service";
12+
import { AuthRegistrationService } from "./auth-registration.service";
1213

1314
@Injectable()
1415
export class AuthSocialService {
1516
constructor(
1617
private readonly usersService: UsersService,
1718
private readonly authService: AuthService,
19+
private readonly authRegistrationService: AuthRegistrationService,
1820
) { }
1921

2022
async signUp(signUpRequestBodyDto: SignUpRequestBodyDto) {
2123
const {
2224
loginType,
2325
snsToken,
24-
email,
25-
phoneNumber,
2626
} = signUpRequestBodyDto;
27-
27+
28+
// 동시성 문제
29+
const isUserRegistered = this.authRegistrationService.isUserRegistered({ loginType, snsToken })
30+
if (!isUserRegistered) {
31+
throw new HttpBadRequestException({
32+
code: AUTH_ERROR_CODE.ACCOUNT_NOT_FOUND,
33+
});
34+
}
35+
2836
const snsProfile = await getSnsProfile(loginType, snsToken);
29-
if (!snsProfile.sns_id) {
37+
if (!snsProfile.snsId) {
3038
throw new HttpInternalServerErrorException({
3139
code: COMMON_ERROR_CODE.SERVER_ERROR,
3240
ctx: '소셜 프로필 조회 중 알 수 없는 에러',
3341
});
3442
}
3543

36-
const existUser = await this.usersService.findOneBy({
37-
loginType,
38-
email: email,
39-
phoneNumber: phoneNumber,
40-
});
41-
42-
if (existUser) {
43-
if (existUser.email.toLowerCase() === email.toLowerCase()) {
44-
throw new HttpConflictException({
45-
code: USER_ERROR_CODE.ALREADY_EXIST_USER_EMAIL,
46-
});
47-
}
48-
if (existUser.phoneNumber === phoneNumber) {
49-
throw new HttpConflictException({
50-
code: USER_ERROR_CODE.ALREADY_EXIST_USER_PHONE_NUMBER,
51-
});
52-
}
53-
}
54-
55-
const user = this.usersService.create({
56-
...signUpRequestBodyDto,
57-
snsId: snsProfile.sns_id,
58-
password: null
44+
const user = await this.usersService.create({
45+
...signUpRequestBodyDto,
46+
snsId: snsProfile.snsId,
47+
password: null
5948
})
6049

6150
return user;
@@ -66,7 +55,7 @@ export class AuthSocialService {
6655

6756
const snsProfile = await getSnsProfile(loginType, snsToken);
6857

69-
if (!snsProfile.sns_id) {
58+
if (!snsProfile.snsId) {
7059
throw new HttpInternalServerErrorException({
7160
code: COMMON_ERROR_CODE.SERVER_ERROR,
7261
ctx: '소셜 프로필 조회 중 알 수 없는 에러',
@@ -75,7 +64,7 @@ export class AuthSocialService {
7564

7665
const existUser = await this.usersService.findOneBy({
7766
loginType,
78-
snsId: snsProfile.sns_id
67+
snsId: snsProfile.snsId
7968
});
8069

8170
if (!existUser) {

src/apis/auth/social/types/auth-social.type.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { UserLoginType } from "@src/apis/users/constants/user.enum";
22

33
export interface SnsProfileBase {
4-
sns_id: string;
4+
snsId: string;
55
}
66

77
export interface SnsProfile extends SnsProfileBase {

src/entities/User.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class User {
8181
comment: '유저 이름',
8282
length: 20
8383
})
84-
name: string;
84+
name: string | null;
8585

8686
@Column('varchar', {
8787
name: 'password',

0 commit comments

Comments
 (0)