@@ -5,7 +5,15 @@ import { JwtUserRefreshGuard } from '../../services/auth/guards/jwt-user-refresh
55import { UserType } from '../../services/token/token.model' ;
66import { UseValidationPipe } from '../../utils/validation.utils' ;
77import { TokenService , TokenServiceProvider } from './../../services/token/token.service' ;
8- import { ConfirmEmailInput , SignInInput , SignUpInput } from './auth.model' ;
8+ import {
9+ ConfirmEmailInput ,
10+ ConfirmEmailResponse ,
11+ HandleRefreshTokenResponse ,
12+ SignInInput ,
13+ SignInResponse ,
14+ SignUpInput ,
15+ SignUpResponse ,
16+ } from './auth.model' ;
917
1018@Controller ( 'api/auth' )
1119export class AuthControllerProvider {
@@ -16,42 +24,40 @@ export class AuthControllerProvider {
1624
1725 @Post ( 'sign-up' )
1826 @UseValidationPipe ( )
19- async signUp ( @Body ( ) body : SignUpInput ) {
20- return mapResponse ( await this . authService . signUp ( body ) ) ( ( ) => ControllerResponse . Success ( ) ) ;
27+ async signUp ( @Body ( ) body : SignUpInput ) : Promise < SignUpResponse > {
28+ return mapResponse (
29+ await this . authService . signUp ( body ) ,
30+ ( ) => new ControllerResponse < never , never > ( ) ,
31+ ) ;
2132 }
2233
2334 @Post ( 'sign-in' )
2435 @UseValidationPipe ( )
25- async signIn ( @Body ( ) body : SignInInput ) {
26- return mapResponse ( await this . authService . signIn ( body ) ) ( ( { accessToken, refreshCookie } ) =>
27- ControllerResponse . Success ( {
28- body : accessToken ,
29- headers : { 'Set-Cookie' : refreshCookie } ,
30- } ) ,
36+ async signIn ( @Body ( ) body : SignInInput ) : Promise < SignInResponse > {
37+ return mapResponse (
38+ await this . authService . signIn ( body ) ,
39+ ( { accessToken, refreshCookie } ) =>
40+ new ControllerResponse ( { token : accessToken } , { 'Set-Cookie' : refreshCookie } ) ,
3141 ) ;
3242 }
3343
3444 @Post ( 'confirm-email' )
3545 @UseValidationPipe ( )
36- async confirmEmail ( @Body ( ) { confirmUuid } : ConfirmEmailInput ) {
37- return mapResponse ( await this . authService . confirmEmail ( confirmUuid ) ) (
46+ async confirmEmail ( @Body ( ) { confirmUuid } : ConfirmEmailInput ) : Promise < ConfirmEmailResponse > {
47+ return mapResponse (
48+ await this . authService . confirmEmail ( confirmUuid ) ,
3849 ( { accessToken, refreshCookie } ) =>
39- ControllerResponse . Success ( {
40- body : accessToken ,
41- headers : { 'Set-Cookie' : refreshCookie } ,
42- } ) ,
50+ new ControllerResponse ( { token : accessToken } , { 'Set-Cookie' : refreshCookie } ) ,
4351 ) ;
4452 }
4553
4654 @Get ( 'refresh' )
4755 @UseGuards ( JwtUserRefreshGuard )
48- async handleRefreshToken ( @User ( ) user : RequestUser ) {
49- return mapResponse ( await this . tokenService . generate ( user . id , UserType . USER , user . email ) ) (
56+ async handleRefreshToken ( @User ( ) user : RequestUser ) : Promise < HandleRefreshTokenResponse > {
57+ return mapResponse (
58+ await this . tokenService . generate ( user . id , UserType . USER , user . email ) ,
5059 ( { accessToken, refreshCookie } ) =>
51- ControllerResponse . Success ( {
52- body : accessToken ,
53- headers : { 'Set-Cookie' : refreshCookie } ,
54- } ) ,
60+ new ControllerResponse ( { token : accessToken } , { 'Set-Cookie' : refreshCookie } ) ,
5561 ) ;
5662 }
5763}
0 commit comments