From aaf41d771316201c8302800b22518f79db6c4c68 Mon Sep 17 00:00:00 2001 From: Shubham Mahobia Date: Thu, 9 May 2024 00:59:25 +0530 Subject: [PATCH] chore: Rename isNewUser to isPatientExist and add isDoctorExist API --- controller/authenticationController.js | 8 +++----- controller/doctorController.js | 18 ++++++++++++++++++ routes/authenticationRoutes.js | 5 ++++- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/controller/authenticationController.js b/controller/authenticationController.js index a1c18a7..4863418 100644 --- a/controller/authenticationController.js +++ b/controller/authenticationController.js @@ -17,17 +17,15 @@ exports.test = (req, res) => { }; //This is the API to check if the user is already registered or not in our system. -exports.isNewUser = async (req, res) => { +exports.isPatientExist = async (req, res) => { try { const isUserExist = await userPatient.findOne({ firebaseUserId: req.body.firebaseUserId, }); if (isUserExist) { - return res - .status(400) - .json({ success: false, message: "User is Present in Database" }); + return res.status(400).json({ success: true, isPresent: true }); } else { - return res.status(200).json({ success: true, message: "User is new" }); + return res.status(200).json({ success: true, isPresent: false }); } } catch (error) { return res diff --git a/controller/doctorController.js b/controller/doctorController.js index 3ba63b6..c9d9d36 100644 --- a/controller/doctorController.js +++ b/controller/doctorController.js @@ -19,6 +19,24 @@ exports.fetchAllDoctors = async (req, res) => { } }; +exports.isDoctorExisit = async (req, res) => { + try { + const isUserExist = await userDoctor.findOne({ + firebaseUserId: req.body.firebaseUserId, + }); + if (isUserExist) { + return res.status(400).json({ success: true, isPresent: true }); + } else { + return res.status(200).json({ success: true, isPresent: false }); + } + } catch (error) { + return res + .status(400) + .json({ success: false, message: "Internal Server Error" }); + } +}; + + // Function to fetch a doctor by ID (firebaseId) exports.fetchDoctorById = async (req, res) => { try { diff --git a/routes/authenticationRoutes.js b/routes/authenticationRoutes.js index fa0f057..ab79188 100644 --- a/routes/authenticationRoutes.js +++ b/routes/authenticationRoutes.js @@ -7,12 +7,14 @@ const { loginUser, fetchUserDetails, fetchDoctorDetails, + isPatientExist, } = require("../controller/authenticationController"); const { fetchAllDoctors, fetchDoctorById, updateDoctorProfile, + isDoctorExisit, } = require("../controller/doctorController"); const { updatePatientProfile } = require("../controller/patientController"); @@ -43,7 +45,8 @@ const router = express.Router(); router.get("/", test); router.post("/registerPatient", signUpPatient); -router.post("/checkNewUser", isNewUser); +router.post("/isPatientExist", isPatientExist); +router.post("/isDoctorExist", isDoctorExisit); router.post("/registerDoctor", signUpDoctor); router.post("/getUser", fetchUserDetails); router.post("/getDoctor", fetchDoctorDetails);