Skip to content
Snippets Groups Projects
Commit a5a646f3 authored by AF7626's avatar AF7626
Browse files

add service folder will not use it at the moment

parent ffd357d3
Branches master
No related tags found
No related merge requests found
// import { addDoctorService } from '../services/adminService.js'; // Import the service
import validator from "validator";
import bcrypt from "bcrypt";
import doctorModel from '../models/doctorModel.js';
......@@ -5,7 +6,11 @@ import doctorModel from '../models/doctorModel.js';
// function to add doctor in the database
const addDoctor = async (req, res) => {
try {
const { name, email, password, speciality, degree, experience, about, fees, address } = req.body;
console.log(req.body)
if (!name || !email || !password || !speciality || !degree || !experience || !about || !fees || !address) {
......@@ -26,7 +31,7 @@ const addDoctor = async (req, res) => {
const salt = await bcrypt.genSalt(5); // the more no. round the more time it will take
const hashedPassword = await bcrypt.hash(password, salt)
//save the data to database
//save the data to database this has to have its own file called adminService
const doctorData = {
name,
......@@ -45,6 +50,12 @@ const addDoctor = async (req, res) => {
await newDoctor.save()
res.json({ success: true, message: 'Doctor Added' })
// // Call the service function to handle doctor creation
// const response = await addDoctorService({ name, email, password, speciality, degree, experience, about, fees, address });
// res.json(response); // Send the response from the service
} catch (error) {
console.log(error);
res.status(500).json({ success: false, message: error.message });
......
import express from 'express';
import { addDoctor } from '../controllers/adminController.js';
// Create a new router instance for handling admin-related routes
const adminRouter = express.Router();
adminRouter.post('/add-doctor',addDoctor);
// This handles POST requests to the endpoint: http://localhost:3000/api/v1/admin/add-doctor
adminRouter.post('/add-doctor', addDoctor);
export default adminRouter;
......
......@@ -14,12 +14,15 @@ connectDB();
// middlewares
// Middleware to parse JSON request bodies
app.use(express.json());
app.use(cors());
//api endpoints use localhost:3000/api/v1/add-doctor
app.use("/api/v1/admin",adminRouter)
// Define API endpoints using base URL: http://localhost:3000/api/v1/admin
// This means all routes inside `adminRouter` will be prefixed with `/api/v1/admin`
app.use("/api/v1/admin", adminRouter);
......
import doctorModel from '../models/doctorModel.js';
import bcrypt from "bcrypt";
//function to for service layer
const addDoctorService = async ({ name, email, password, speciality, degree, experience, about, fees, address }) => {
try {
// hashing user password
const salt = await bcrypt.genSalt(5); // the more rounds, the more time it will take
const hashedPassword = await bcrypt.hash(password, salt);
// Save the data to database
const doctorData = {
name,
email,
password: hashedPassword,
speciality,
degree,
experience,
about,
fees,
address,
date: Date.now(),
};
const newDoctor = new doctorModel(doctorData);
await newDoctor.save();
return { success: true, message: 'Doctor Added' };
} catch (error) {
console.log(error);
return { success: false, message: error.message };
}
};
export { addDoctorService };
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment