add , edit, configure specialist
This commit is contained in:
parent
b6486e994b
commit
bf3b4ba50c
41
app.js
41
app.js
@ -1,36 +1,36 @@
|
||||
|
||||
import dotenv from "dotenv";
|
||||
import express from 'express'
|
||||
import express from "express";
|
||||
const app = express();
|
||||
import bodyParser from "body-parser";
|
||||
import fileUpload from "express-fileupload"// important pkg for file upload
|
||||
import cors from 'cors'
|
||||
import cookieParser from "cookie-parser"
|
||||
import fileUpload from "express-fileupload"; // important pkg for file upload
|
||||
import cors from "cors";
|
||||
import cookieParser from "cookie-parser";
|
||||
|
||||
// app.use(express.json({ limit: "50mb" }));
|
||||
// app.use(express.urlencoded({ extended: true, limit: "50mb" }));
|
||||
app.use(cookieParser());
|
||||
|
||||
|
||||
//handdle cores
|
||||
app.use(cors())
|
||||
app.use(express.json())
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
app.use(bodyParser.urlencoded({ extended: true }));
|
||||
app.use(fileUpload({
|
||||
useTempFiles: true
|
||||
}));
|
||||
app.use(
|
||||
fileUpload({
|
||||
useTempFiles: true,
|
||||
})
|
||||
);
|
||||
|
||||
//auth
|
||||
import user from "./resources/user/userRoute.js"
|
||||
import user from "./resources/user/userRoute.js";
|
||||
import ProductRouter from "./resources/Products/ProductRoute.js";
|
||||
//Businesses
|
||||
import BusinessRoute from "./resources/Businesses/BusinessRoute.js";
|
||||
|
||||
import orderRoute from './resources/Orders/orderRoute.js';
|
||||
import orderRoute from "./resources/Orders/orderRoute.js";
|
||||
import DepartureRouter from "./resources/Departure/DepartureRoute.js";
|
||||
import InformationRoute from "./resources/Informations/InformationRoute.js";
|
||||
import Testimonial from "./resources/Testimonials/TestimonialRoute.js";
|
||||
import ContactRequest from "./resources/ContactRequests/ContactRequestRoute.js"
|
||||
import ContactRequest from "./resources/ContactRequests/ContactRequestRoute.js";
|
||||
|
||||
import StateRouter from "./resources/setting/state/state_routes.js";
|
||||
//
|
||||
@ -43,6 +43,11 @@ import Business_TypeRoute from "./resources/setting/Business_Type/Business_route
|
||||
import ConfigRouter from "./resources/setting/Configration/Config_routes.js";
|
||||
|
||||
import TaxRouter from "./resources/Tax/tax_routes.js";
|
||||
//specialties
|
||||
import SpecialtiesRouter from "./resources/Specialties/SpecialtiesRoute.js";
|
||||
//specialist
|
||||
import SpecialistRouter from "./resources/Specialist/SpecialistRoute.js";
|
||||
|
||||
app.use("/api/v1/", user);
|
||||
|
||||
//Product
|
||||
@ -70,6 +75,10 @@ app.use("/api/business", Business_TypeRoute);
|
||||
//Tax
|
||||
app.use("/api/tax", TaxRouter);
|
||||
//config
|
||||
app.use("/api/config", ConfigRouter)
|
||||
app.use("/api/config", ConfigRouter);
|
||||
//config specialty
|
||||
app.use("/api/config/specialty", SpecialtiesRouter);
|
||||
//specialties
|
||||
app.use("/api/specialist", SpecialistRouter);
|
||||
|
||||
export default app;
|
||||
export default app;
|
||||
|
101
resources/Specialist/SpecialistController.js
Normal file
101
resources/Specialist/SpecialistController.js
Normal file
@ -0,0 +1,101 @@
|
||||
import catchAsyncErrors from "../../middlewares/catchAsyncErrors.js";
|
||||
import { Specialist } from "./SpecialistModel.js";
|
||||
|
||||
// create a new specialist
|
||||
// POST /api/specialist
|
||||
export const createSpecialist = async (req, res, next) => {
|
||||
try {
|
||||
const specialist = await Specialist.create(req.body);
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
specialist,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
message: error.message,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// get all specialists
|
||||
// GET /api/specialist
|
||||
export const getAllSpecialist = catchAsyncErrors(async (req, res, next) => {
|
||||
const specialist = await Specialist.find();
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
specialist,
|
||||
});
|
||||
});
|
||||
|
||||
// get a single specialist
|
||||
// GET /api/specialist/:id
|
||||
export const getSingleSpecialist = catchAsyncErrors(async (req, res, next) => {
|
||||
const specialist = await Specialist.findById(req.params.id);
|
||||
|
||||
if (!specialist) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: "Specialist not found",
|
||||
});
|
||||
}
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
specialist,
|
||||
});
|
||||
});
|
||||
|
||||
// update a single specialist
|
||||
// PUT /api/specialist/:id
|
||||
export const updateSpecialist = async (req, res, next) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const update = req.body;
|
||||
const options = { new: true };
|
||||
|
||||
const updatedSpecialist = await Specialist.findByIdAndUpdate(
|
||||
id,
|
||||
update,
|
||||
options
|
||||
);
|
||||
|
||||
if (!updatedSpecialist) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: "Specialist not found",
|
||||
});
|
||||
}
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
updatedSpecialist,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error.message,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// delete a single specialist
|
||||
// DELETE /api/specialist/:id
|
||||
export const deleteSpecialist = catchAsyncErrors(async (req, res, next) => {
|
||||
const specialist = await Specialist.findById(req.params.id);
|
||||
|
||||
if (!specialist) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: "Specialist not found",
|
||||
});
|
||||
}
|
||||
|
||||
await specialist.remove();
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
message: "Specialist deleted successfully",
|
||||
});
|
||||
});
|
68
resources/Specialist/SpecialistModel.js
Normal file
68
resources/Specialist/SpecialistModel.js
Normal file
@ -0,0 +1,68 @@
|
||||
import { mongoose } from "mongoose";
|
||||
|
||||
// specialistName: "",
|
||||
// specialty: "",
|
||||
// location: "",
|
||||
// daysAvailable: daysAvailable,
|
||||
// phone: "",
|
||||
|
||||
const daysAvailableSchema = new mongoose.Schema({
|
||||
label: {
|
||||
type: String,
|
||||
required: true,
|
||||
enum: [
|
||||
"Monday",
|
||||
"Tuesday",
|
||||
"Wednesday",
|
||||
"Thursday",
|
||||
"Friday",
|
||||
"Saturday",
|
||||
"Sunday",
|
||||
],
|
||||
},
|
||||
available: {
|
||||
type: Boolean,
|
||||
required: true,
|
||||
default: false,
|
||||
},
|
||||
timeSlots: [
|
||||
{
|
||||
startTime: String,
|
||||
endTime: String,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const specialistSchema = new mongoose.Schema({
|
||||
specialistName: {
|
||||
type: String,
|
||||
required: [true, "Please enter specialist name"],
|
||||
trim: true,
|
||||
maxlength: [100, "Specialist name cannot exceed 100 characters"],
|
||||
},
|
||||
specialty: {
|
||||
type: String,
|
||||
required: [true, "Please enter specialty name"],
|
||||
trim: true,
|
||||
maxlength: [100, "Specialty name cannot exceed 100 characters"],
|
||||
},
|
||||
location: {
|
||||
type: String,
|
||||
trim: true,
|
||||
maxlength: [100, "Location cannot exceed 100 characters"],
|
||||
},
|
||||
daysAvailable: {
|
||||
type: [daysAvailableSchema],
|
||||
},
|
||||
phone: {
|
||||
type: String,
|
||||
trim: true,
|
||||
maxlength: [100, "Phone number cannot exceed 100 characters"],
|
||||
},
|
||||
createdAt: {
|
||||
type: Date,
|
||||
default: Date.now,
|
||||
},
|
||||
});
|
||||
|
||||
export const Specialist = mongoose.model("Specialist", specialistSchema);
|
23
resources/Specialist/SpecialistRoute.js
Normal file
23
resources/Specialist/SpecialistRoute.js
Normal file
@ -0,0 +1,23 @@
|
||||
import { Router } from "express";
|
||||
import {
|
||||
isAuthenticatedUser,
|
||||
authorizeRoles,
|
||||
isBusinessAuthenticated,
|
||||
} from "../../middlewares/auth.js";
|
||||
import {
|
||||
createSpecialist,
|
||||
deleteSpecialist,
|
||||
getAllSpecialist,
|
||||
getSingleSpecialist,
|
||||
updateSpecialist,
|
||||
} from "./SpecialistController.js";
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.route("/add").post(createSpecialist);
|
||||
router.route("/getall").get(getAllSpecialist);
|
||||
router.route("/get/:id").get(getSingleSpecialist);
|
||||
router.route("/delete/:id").delete(deleteSpecialist);
|
||||
router.route("/update/:id").patch(updateSpecialist);
|
||||
|
||||
export default router;
|
68
resources/Specialties/SpecialtiesController.js
Normal file
68
resources/Specialties/SpecialtiesController.js
Normal file
@ -0,0 +1,68 @@
|
||||
import catchAsyncErrors from "../../middlewares/catchAsyncErrors.js";
|
||||
import { Specialty } from "./SpecialtiesModel.js";
|
||||
|
||||
// add a new specialty
|
||||
// POST /api/specialty/add
|
||||
export const createSpecialty = async (req, res, next) => {
|
||||
try {
|
||||
const specialty = await Specialty.create(req.body);
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
specialty,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
message: error.message,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// get all specialties
|
||||
// GET /api/specialty
|
||||
export const getAllSpecialty = catchAsyncErrors(async (req, res, next) => {
|
||||
const specialty = await Specialty.find();
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
specialty,
|
||||
});
|
||||
});
|
||||
|
||||
// get a single specialty
|
||||
// GET /api/specialty/:id
|
||||
export const getSingleSpecialty = catchAsyncErrors(async (req, res, next) => {
|
||||
const specialty = await Specialty.findById(req.params.id);
|
||||
|
||||
if (!specialty) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: "Specialty not found",
|
||||
});
|
||||
}
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
specialty,
|
||||
});
|
||||
});
|
||||
|
||||
// delete a single specialty
|
||||
// DELETE /api/specialty/:id
|
||||
export const deleteSpecialty = catchAsyncErrors(async (req, res, next) => {
|
||||
const specialty = await Specialty.findById(req.params.id);
|
||||
|
||||
if (!specialty) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: "Specialty not found",
|
||||
});
|
||||
}
|
||||
|
||||
await specialty.remove();
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
message: "Specialty deleted",
|
||||
});
|
||||
});
|
16
resources/Specialties/SpecialtiesModel.js
Normal file
16
resources/Specialties/SpecialtiesModel.js
Normal file
@ -0,0 +1,16 @@
|
||||
import { mongoose } from "mongoose";
|
||||
|
||||
const specialtySchema = new mongoose.Schema({
|
||||
name: {
|
||||
type: String,
|
||||
required: [true, "Please enter specialty name"],
|
||||
trim: true,
|
||||
maxlength: [100, "Specialty name cannot exceed 100 characters"],
|
||||
},
|
||||
createdAt: {
|
||||
type: Date,
|
||||
default: Date.now,
|
||||
},
|
||||
});
|
||||
|
||||
export const Specialty = mongoose.model("Specialty", specialtySchema);
|
21
resources/Specialties/SpecialtiesRoute.js
Normal file
21
resources/Specialties/SpecialtiesRoute.js
Normal file
@ -0,0 +1,21 @@
|
||||
import { Router } from "express";
|
||||
import {
|
||||
isAuthenticatedUser,
|
||||
authorizeRoles,
|
||||
isBusinessAuthenticated,
|
||||
} from "../../middlewares/auth.js";
|
||||
import {
|
||||
createSpecialty,
|
||||
deleteSpecialty,
|
||||
getAllSpecialty,
|
||||
getSingleSpecialty,
|
||||
} from "./SpecialtiesController.js";
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.route("/add").post(createSpecialty);
|
||||
router.route("/getall").get(getAllSpecialty);
|
||||
router.route("/get/:id").get(getSingleSpecialty);
|
||||
router.route("/delete/:id").delete(deleteSpecialty);
|
||||
|
||||
export default router;
|
Loading…
Reference in New Issue
Block a user