-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from ShubhaMahobia/14-fetch-all-doctors
implemented the fetch all doctors API
- Loading branch information
Showing
3 changed files
with
104 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const express = require("express"); | ||
const bcrypt = require("bcryptjs"); | ||
const userDoctor = require("../model/UserDoctorModel"); | ||
const mongoose = require("mongoose"); | ||
|
||
//Function for fetching all the doctors | ||
exports.fetchAllDoctors = async (req, res) => { | ||
try { | ||
const allDoctors = await userDoctor.find({}); | ||
return res.status(200).json({ | ||
success: true, | ||
message: "Details fetched successfully", | ||
data: allDoctors, | ||
}); | ||
} catch (err) { | ||
return res | ||
.status(500) | ||
.json({ success: false, message: "Internal Server Error" }); | ||
} | ||
}; | ||
|
||
// Function to fetch a doctor by ID (firebaseId) | ||
exports.fetchDoctorById = async (req, res) => { | ||
try { | ||
const doctorId = req.params.id; // Assuming the ID is passed as a route parameter | ||
const doctor = await userDoctor.findOne({ firebaseUserId: doctorId }); // Changed to findOne with firebaseUserId | ||
if (!doctor) { | ||
return res | ||
.status(404) | ||
.json({ success: false, message: "Doctor not found" }); | ||
} | ||
|
||
return res.status(200).json({ | ||
success: true, | ||
message: "Doctor details fetched successfully", | ||
data: doctor, | ||
}); | ||
} catch (err) { | ||
return res | ||
.status(500) | ||
.json({ success: false, message: "Internal Server Error" }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters