@@ -2,8 +2,7 @@ const express = require("express");
2
2
const userPatient = require ( "../model/UserPatientModel" ) ;
3
3
const bcrypt = require ( "bcryptjs" ) ;
4
4
const userDoctor = require ( "../model/UserDoctorModel" ) ;
5
- const mongoose = require ( 'mongoose' ) ;
6
-
5
+ const mongoose = require ( "mongoose" ) ;
7
6
8
7
//This is a test function to check is the server is running or not.
9
8
exports . test = ( req , res ) => {
@@ -39,15 +38,14 @@ exports.isNewUser = async (req, res) => {
39
38
//This is the create Profile Function for the user(Patient)
40
39
exports . signUpPatient = async ( req , res ) => {
41
40
try {
42
-
43
41
//Here we are saving the identification number in encrypted form so that it will be secured in our database
44
42
const identificationNumber = req . body . identificationNumber ;
45
43
const hashedIdentificationNumber = await bcrypt . hash (
46
44
identificationNumber ,
47
45
12
48
46
) ;
49
47
50
- //Creating patient Object
48
+ //Creating patient Object
51
49
const patient = new userPatient ( {
52
50
firebaseUserId : req . body . firebaseUserId ,
53
51
firstName : req . body . firstName ,
@@ -82,19 +80,18 @@ exports.signUpPatient = async (req, res) => {
82
80
message : "Internal Server Error" ,
83
81
} ) ;
84
82
}
85
- }
83
+ } ;
86
84
//This is the create Profile Function for the user(Doctor)
87
85
exports . signUpDoctor = async ( req , res ) => {
88
86
try {
89
-
90
87
//Here we are saving the identification number in encrypted form so that it will be secured in our database
91
88
const identificationNumber = req . body . identificationNumber ;
92
89
const hashedIdentificationNumber = await bcrypt . hash (
93
90
identificationNumber ,
94
91
12
95
92
) ;
96
93
97
- //Creating Doctor Object
94
+ //Creating Doctor Object
98
95
const doctor = new userDoctor ( {
99
96
firebaseUserId : req . body . firebaseUserId ,
100
97
firstName : req . body . firstName ,
@@ -130,54 +127,62 @@ exports.signUpDoctor = async (req, res) => {
130
127
message : "Internal Server Error" ,
131
128
} ) ;
132
129
}
133
- }
130
+ } ;
134
131
135
- //Login Fuction for fetching user Patient details
136
- exports . fetchUserDetails = async ( req , res ) => {
137
- try {
138
- const email = req . body . email ;
139
- if ( email == null ) {
140
- return res . status ( 400 ) . json ( { success :false , message :"Please provide an email" } ) ;
132
+ //Login Fuction for fetching user Patient details
133
+ exports . fetchUserDetails = async ( req , res ) => {
134
+ try {
135
+ const email = req . body . email ;
136
+ if ( email == null ) {
137
+ return res
138
+ . status ( 400 )
139
+ . json ( { success : false , message : "Please provide an email" } ) ;
140
+ } else {
141
+ const user = await userPatient . findOne ( { Email : email } ) ;
142
+ if ( ! user ) {
143
+ return res . status ( 401 ) . json ( {
144
+ success : false ,
145
+ message : "Authentication failed! Email not found." ,
146
+ } ) ;
147
+ } else {
148
+ return res
149
+ . status ( 401 )
150
+ . json ( { success : true , data : user , message : "User success" } ) ;
151
+ }
141
152
}
142
- else {
143
- const user = await userPatient . findOne ( { Email :email } ) ;
144
- if ( ! user ) {
145
- return res . status ( 401 ) . json ( { success :false , message :"Authentication failed! Email not found." } ) ;
146
- }
147
- else {
148
- return res . status ( 401 ) . json ( { success :true , data : user , message :"User success" } ) ;
149
- }
150
- }
151
-
152
-
153
153
} catch ( err ) {
154
- return res . status ( 500 ) . json ( { success :false , message :"Internal Server Error" } ) ;
155
-
154
+ return res
155
+ . status ( 500 )
156
+ . json ( { success : false , message : "Internal Server Error" } ) ;
156
157
}
157
- }
158
-
158
+ } ;
159
159
160
160
//Login Fuction for fetching user Doctor details
161
- exports . fetchDoctorDetails = async ( req , res ) => {
162
- try {
163
- const email = req . body . email ;
164
- if ( email == null ) {
165
- return res . status ( 400 ) . json ( { success :false , message :"Please provide an email" } ) ;
161
+ exports . fetchDoctorDetails = async ( req , res ) => {
162
+ try {
163
+ const email = req . body . email ;
164
+ if ( email == null ) {
165
+ return res
166
+ . status ( 400 )
167
+ . json ( { success : false , message : "Please provide an email" } ) ;
168
+ } else {
169
+ const user = await userDoctor . findOne ( { Email : email } ) ;
170
+ if ( ! user ) {
171
+ return res . status ( 401 ) . json ( {
172
+ success : false ,
173
+ message : "Authentication failed! Email not found." ,
174
+ } ) ;
175
+ } else {
176
+ return res
177
+ . status ( 401 )
178
+ . json ( { success : true , data : user , message : "User success" } ) ;
179
+ }
166
180
}
167
- else {
168
- const user = await userDoctor . findOne ( { Email :email } ) ;
169
- if ( ! user ) {
170
- return res . status ( 401 ) . json ( { success :false , message :"Authentication failed! Email not found." } ) ;
171
- }
172
- else {
173
- return res . status ( 401 ) . json ( { success :true , data : user , message :"User success" } ) ;
174
- }
175
- }
176
-
177
-
178
181
} catch ( err ) {
179
- return res . status ( 500 ) . json ( { success :false , message :"Internal Server Error" } ) ;
180
-
182
+ return res
183
+ . status ( 500 )
184
+ . json ( { success : false , message : "Internal Server Error" } ) ;
181
185
}
182
- }
186
+ } ;
187
+
183
188
0 commit comments