@@ -63,37 +63,46 @@ class AuthService {
63
63
private async checkIsExistingUser ( {
64
64
email,
65
65
phone,
66
- } : CustomerSignUpRequestDto | BusinessSignUpRequestDto ) : Promise < boolean > {
66
+ } : CustomerSignUpRequestDto | BusinessSignUpRequestDto ) : Promise < void > {
67
67
const existingUser = await this . userService . findByPhoneOrEmail (
68
68
phone ,
69
69
email ,
70
70
) ;
71
71
72
- return Boolean ( existingUser ) ;
72
+ if ( email === existingUser ?. email ) {
73
+ throw new HttpError ( {
74
+ message : HttpMessage . USER_EMAIL_EXISTS ,
75
+ status : HttpCode . CONFLICT ,
76
+ } ) ;
77
+ }
78
+
79
+ if ( phone === existingUser ?. phone ) {
80
+ throw new HttpError ( {
81
+ message : HttpMessage . USER_PHONE_EXISTS ,
82
+ status : HttpCode . CONFLICT ,
83
+ } ) ;
84
+ }
73
85
}
74
86
75
87
private async checkIsExistingBusiness ( {
76
88
taxNumber,
77
- } : BusinessSignUpRequestDto ) : Promise < boolean > {
89
+ } : BusinessSignUpRequestDto ) : Promise < void > {
78
90
const existingBusiness = await this . businessService . checkIsExistingBusiness (
79
91
{ taxNumber } ,
80
92
) ;
81
93
82
- return Boolean ( existingBusiness ) ;
83
- }
84
-
85
- public async signUpCustomer (
86
- payload : CustomerSignUpRequestDto ,
87
- ) : Promise < UserEntityObjectWithGroupT > {
88
- const isExistingUser = await this . checkIsExistingUser ( payload ) ;
89
-
90
- if ( isExistingUser ) {
94
+ if ( existingBusiness ) {
91
95
throw new HttpError ( {
92
- message : HttpMessage . USER_EXISTS ,
96
+ message : HttpMessage . BUSINESS_EXISTS ,
93
97
status : HttpCode . CONFLICT ,
94
98
} ) ;
95
99
}
100
+ }
96
101
102
+ public async signUpCustomer (
103
+ payload : CustomerSignUpRequestDto ,
104
+ ) : Promise < UserEntityObjectWithGroupT > {
105
+ await this . checkIsExistingUser ( payload ) ;
97
106
const group = await this . groupService . findByKey ( UserGroupKey . CUSTOMER ) ;
98
107
99
108
if ( ! group ) {
@@ -106,7 +115,6 @@ class AuthService {
106
115
...payload ,
107
116
groupId : group . id ,
108
117
} ) ;
109
-
110
118
const userWithToken = await this . generateAccessTokenAndUpdateUser (
111
119
newUser . id ,
112
120
) ;
@@ -117,22 +125,8 @@ class AuthService {
117
125
public async signUpBusiness (
118
126
payload : BusinessSignUpRequestDto ,
119
127
) : Promise < UserEntityObjectWithGroupAndBusinessT > {
120
- const isExistingUser = await this . checkIsExistingUser ( payload ) ;
121
- const isExistingBusiness = await this . checkIsExistingBusiness ( payload ) ;
122
-
123
- if ( isExistingUser ) {
124
- throw new HttpError ( {
125
- message : HttpMessage . USER_EXISTS ,
126
- status : HttpCode . CONFLICT ,
127
- } ) ;
128
- }
129
-
130
- if ( isExistingBusiness ) {
131
- throw new HttpError ( {
132
- message : HttpMessage . BUSINESS_EXISTS ,
133
- status : HttpCode . CONFLICT ,
134
- } ) ;
135
- }
128
+ await this . checkIsExistingUser ( payload ) ;
129
+ await this . checkIsExistingBusiness ( payload ) ;
136
130
137
131
const {
138
132
phone,
0 commit comments