@@ -2,8 +2,9 @@ import { Router } from "express";
22import authService from "../services/authService" ;
33import { asyncHandle } from "../utils/asyncHandler" ;
44import cookieConfig from "../config/cookie.config" ;
5- import createToken from "../utils/token.utils" ;
5+ import createToken , { Payload } from "../utils/token.utils" ;
66import upload from "../utils/multer" ;
7+ import passport from "passport" ;
78
89const router = Router ( ) ;
910
@@ -75,18 +76,19 @@ router.post(
7576 upload . single ( "imageUrl" ) ,
7677 asyncHandle ( async ( req , res , next ) => {
7778 try {
78- const SignUpCustomer : SignUpCustomer = {
79+ const signUpCustomer : SignUpCustomer = {
7980 ...req . body ,
8081 imageUrl : req . file ! ,
8182 services : Array . isArray ( req . body . services )
82- ? req . body . services
83- : JSON . parse ( req . body . services ) ,
83+ ? req . body . services . map ( Number )
84+ : JSON . parse ( req . body . services ) . map ( Number ) ,
8485 regions : Array . isArray ( req . body . regions )
85- ? req . body . regions
86- : JSON . parse ( req . body . regions ) ,
86+ ? req . body . regions . map ( Number )
87+ : JSON . parse ( req . body . regions ) . map ( Number ) ,
8788 isOAuth : req . body . isOAuth === "true" ,
8889 } ;
89- await authService . signUpCustomer ( SignUpCustomer ) ;
90+
91+ await authService . signUpCustomer ( signUpCustomer ) ;
9092 res . status ( 204 ) . send ( ) ;
9193 } catch ( error ) {
9294 next ( error ) ;
@@ -99,7 +101,18 @@ router.post(
99101 upload . single ( "imageUrl" ) ,
100102 asyncHandle ( async ( req , res , next ) => {
101103 try {
102- const SignUpMover : SignUpMover = req . body ;
104+ const SignUpMover : SignUpMover = {
105+ ...req . body ,
106+ imageUrl : req . file ! ,
107+ services : Array . isArray ( req . body . services )
108+ ? req . body . services . map ( Number )
109+ : JSON . parse ( req . body . services ) . map ( Number ) ,
110+ regions : Array . isArray ( req . body . regions )
111+ ? req . body . regions . map ( Number )
112+ : JSON . parse ( req . body . regions ) . map ( Number ) ,
113+ isOAuth : req . body . isOAuth === "true" ,
114+ career : Number ( req . body . career ) ,
115+ } ;
103116 await authService . signUpMover ( SignUpMover ) ;
104117 res . status ( 204 ) . send ( ) ;
105118 } catch ( error ) {
@@ -108,4 +121,32 @@ router.post(
108121 } )
109122) ;
110123
124+ router . post (
125+ "/validate" ,
126+ asyncHandle ( async ( req , res , next ) => {
127+ try {
128+ const { email, phoneNumber } = req . body ;
129+ await authService . validate ( email , phoneNumber ) ;
130+ res . status ( 204 ) . send ( ) ;
131+ } catch ( error ) {
132+ next ( error ) ;
133+ }
134+ } )
135+ ) ;
136+
137+ router . post (
138+ "/refresh" ,
139+ passport . authenticate ( "refresh-token" , { session : false } ) ,
140+ asyncHandle ( async ( req , res , next ) => {
141+ try {
142+ const user = req . user as Payload ;
143+ const accessToken = createToken ( user , "access" ) ;
144+ res . cookie ( "accessToken" , accessToken , cookieConfig . accessTokenOption ) ;
145+ res . status ( 204 ) . send ( ) ;
146+ } catch ( error ) {
147+ next ( error ) ;
148+ }
149+ } )
150+ ) ;
151+
111152export default router ;
0 commit comments