@@ -13,9 +13,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
} ;
14
14
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
15
15
const express_1 = __importDefault ( require ( "express" ) ) ;
16
- const db_1 = require ( "../db" ) ;
17
16
const jsonwebtoken_1 = require ( "jsonwebtoken" ) ;
18
17
const authMiddleware_1 = require ( "../middleware/authMiddleware" ) ;
18
+ const auth_1 = require ( "../repositories/auth" ) ;
19
19
const router = express_1 . default . Router ( ) ;
20
20
router . post ( "/auth/signup" , ( req , res ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
21
21
console . log ( "request recived" ) ;
@@ -31,17 +31,16 @@ router.post("/auth/signup", (req, res) => __awaiter(void 0, void 0, void 0, func
31
31
} ) ;
32
32
}
33
33
try {
34
- const user = yield db_1 . prisma . user . create ( {
35
- data : {
36
- name,
37
- gender,
38
- email,
39
- password,
40
- phone_number,
41
- } ,
34
+ const user = yield ( 0 , auth_1 . create ) ( {
35
+ name,
36
+ gender,
37
+ email,
38
+ password,
39
+ phone_number,
42
40
} ) ;
43
41
res . status ( 200 ) . json ( {
44
42
message : "user created successfully" ,
43
+ user,
45
44
} ) ;
46
45
}
47
46
catch ( error ) {
@@ -51,13 +50,9 @@ router.post("/auth/signup", (req, res) => __awaiter(void 0, void 0, void 0, func
51
50
} ) ;
52
51
}
53
52
} ) ) ;
54
- router . post ( ' /auth/signin' , ( req , res ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
53
+ router . post ( " /auth/signin" , ( req , res ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
55
54
const { email, password } = req . body ;
56
- const user = yield db_1 . prisma . user . findUnique ( {
57
- where : {
58
- email : email
59
- }
60
- } ) ;
55
+ const user = yield ( 0 , auth_1 . findUnique ) ( email ) ;
61
56
console . log ( user ) ;
62
57
if ( ! user ) {
63
58
return res . status ( 411 ) . json ( {
@@ -66,42 +61,33 @@ router.post('/auth/signin', (req, res) => __awaiter(void 0, void 0, void 0, func
66
61
}
67
62
if ( user . password != password ) {
68
63
return res . status ( 411 ) . json ( {
69
- message : "incorrect password"
64
+ message : "incorrect password" ,
70
65
} ) ;
71
66
}
72
67
const token = ( 0 , jsonwebtoken_1 . sign ) ( user . id , "secret" ) ;
73
68
return res . status ( 200 ) . json ( {
74
69
message : "user logged in sucessfully" ,
75
- token
70
+ token,
76
71
} ) ;
77
72
} ) ) ;
78
- router . put ( ' /update' , authMiddleware_1 . authMiddleware , ( req , res ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
73
+ router . put ( " /update" , authMiddleware_1 . authMiddleware , ( req , res ) => __awaiter ( void 0 , void 0 , void 0 , function * ( ) {
79
74
try {
80
75
const { name, password, phone_number } = req . body ;
81
76
const userId = req . userId ;
82
77
if ( ! userId ) {
83
78
return res . status ( 411 ) . json ( {
84
- message : "userId is not present"
79
+ message : "userId is not present" ,
85
80
} ) ;
86
81
}
87
- const user = yield db_1 . prisma . user . update ( {
88
- where : {
89
- id : userId
90
- } ,
91
- data : {
92
- name,
93
- password,
94
- phone_number
95
- }
96
- } ) ;
82
+ const user = yield ( 0 , auth_1 . Update ) ( { name, password, phone_number, userId } ) ;
97
83
return res . status ( 200 ) . json ( {
98
84
message : "user updated Sucessfully" ,
99
- user
85
+ user,
100
86
} ) ;
101
87
}
102
88
catch ( error ) {
103
89
res . status ( 411 ) . json ( {
104
- message : "error while updating the user"
90
+ message : "error while updating the user" ,
105
91
} ) ;
106
92
}
107
93
} ) ) ;
0 commit comments