File tree Expand file tree Collapse file tree 5 files changed +27
-5
lines changed
Expand file tree Collapse file tree 5 files changed +27
-5
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ async function bootstrap() {
1313 const httpServer = app . getHttpServer ( ) ;
1414 app . useWebSocketAdapter ( new IoAdapter ( httpServer ) ) ;
1515
16- const port = process . env . PORT || 3000 ;
16+ const port = process . env . PORT || 3030 ;
1717 await app . listen ( port ) ;
1818}
1919
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ export class AuthGuard implements CanActivate {
3737 const payload = await this . jwtService . verifyAsync ( token , {
3838 secret : jwtConstants . secret ,
3939 } ) ;
40+ console . log ( { payload } ) ;
4041 const user = await this . usersService . _get ( payload . sub . id ) ;
4142 // 💡 We're assigning the payload to the request object here
4243 // so that we can access it in our route handlers
Original file line number Diff line number Diff line change @@ -35,13 +35,18 @@ export class Users extends SoftDeleteSchema {
3535 } )
3636 lastName : string ;
3737
38+ @Prop ( {
39+ type : Number ,
40+ enum : [ 1 , 4096 ] ,
41+ } )
42+ type : number ;
43+
3844 @Prop ( {
3945 type : String ,
4046 trim : true ,
4147 required : true ,
4248 unique : true ,
4349 index : true ,
44- match : / ^ [ 0 - 9 ] { 10 } $ / ,
4550 } )
4651 phone : string ;
4752
Original file line number Diff line number Diff line change @@ -35,12 +35,29 @@ export class UsersController {
3535 return await this . usersService . _get ( id , query ) ;
3636 }
3737
38- @Public ( )
3938 @Post ( )
40- async create ( @Body ( ) createUsersDto : Users ) {
39+ async create ( @Body ( ) createUsersDto : Users , @ User ( ) users : Users ) {
4140 /**
4241 * @todo use zod for validations...
4342 */
43+ const saltOrRounds = 10 ;
44+ console . log ( { users } ) ;
45+ if ( users . type === 4096 ) {
46+ const password = await bcrypt . hash ( createUsersDto . password , saltOrRounds ) ;
47+
48+ const user = ( await this . usersService . _create ( {
49+ ...createUsersDto ,
50+ password,
51+ } ) ) as Users ;
52+
53+ const sanitizedUser = this . usersService . sanitizeUser ( user ) ;
54+ const payload = { sub : { id : user . _id } , user } ;
55+
56+ return {
57+ user : sanitizedUser ,
58+ accessToken : await this . jwtService . signAsync ( payload ) ,
59+ } ;
60+ }
4461 if ( ! createUsersDto . email || ! createUsersDto [ 'otp' ] ) {
4562 throw new BadRequestException ( 'Email or OTP not provided!' ) ;
4663 }
@@ -53,7 +70,6 @@ export class UsersController {
5370 true , // removeEntryAfterCheck
5471 ) ;
5572
56- const saltOrRounds = 10 ;
5773 const password = await bcrypt . hash ( createUsersDto . password , saltOrRounds ) ;
5874
5975 const user = ( await this . usersService . _create ( {
You can’t perform that action at this time.
0 commit comments