added business id for appointmnet and doctors removed purpose
This commit is contained in:
parent
dc7dbeeddc
commit
ac12d5dfd4
@ -7,7 +7,14 @@ const { Types } = pkg;
|
|||||||
export const createAppointment = async (req, res, next) => {
|
export const createAppointment = async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const doctorId = Types.ObjectId(req.body.doctorId);
|
const doctorId = Types.ObjectId(req.body.doctorId);
|
||||||
const { doctorName, date, time, patientName, patientPhone } = req.body;
|
const {
|
||||||
|
doctorName,
|
||||||
|
date,
|
||||||
|
time,
|
||||||
|
patientName,
|
||||||
|
patientPhone,
|
||||||
|
HealthCareProviderID,
|
||||||
|
} = req.body;
|
||||||
const appointment = await Appointment.create({
|
const appointment = await Appointment.create({
|
||||||
doctorId,
|
doctorId,
|
||||||
doctorName,
|
doctorName,
|
||||||
@ -15,6 +22,7 @@ export const createAppointment = async (req, res, next) => {
|
|||||||
time,
|
time,
|
||||||
patientName,
|
patientName,
|
||||||
patientPhone,
|
patientPhone,
|
||||||
|
HealthCareProviderID,
|
||||||
});
|
});
|
||||||
res.status(201).json({
|
res.status(201).json({
|
||||||
success: true,
|
success: true,
|
||||||
|
@ -12,6 +12,12 @@ import { Specialist } from "./../Specialist/SpecialistModel.js";
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
const appointmentSchema = new mongoose.Schema({
|
const appointmentSchema = new mongoose.Schema({
|
||||||
|
HealthCareProviderID: {
|
||||||
|
type: mongoose.Schema.ObjectId,
|
||||||
|
ref: "Businesses",
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
|
||||||
doctorId: {
|
doctorId: {
|
||||||
type: mongoose.Schema.Types.ObjectId,
|
type: mongoose.Schema.Types.ObjectId,
|
||||||
ref: Specialist,
|
ref: Specialist,
|
||||||
|
@ -15,7 +15,7 @@ export const createBusiness = async (req, res) => {
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
business,
|
business,
|
||||||
purpose,
|
specialization,
|
||||||
country,
|
country,
|
||||||
language,
|
language,
|
||||||
state,
|
state,
|
||||||
@ -34,8 +34,6 @@ export const createBusiness = async (req, res) => {
|
|||||||
switch (true) {
|
switch (true) {
|
||||||
case !business:
|
case !business:
|
||||||
return res.status(500).send({ error: "Business is Required" });
|
return res.status(500).send({ error: "Business is Required" });
|
||||||
case !purpose:
|
|
||||||
return res.status(500).send({ error: "Purpose is Required" });
|
|
||||||
case !language:
|
case !language:
|
||||||
return res.status(500).send({ error: "Language is Required" });
|
return res.status(500).send({ error: "Language is Required" });
|
||||||
case !address_Line_1:
|
case !address_Line_1:
|
||||||
@ -50,22 +48,22 @@ export const createBusiness = async (req, res) => {
|
|||||||
return res.status(500).send({ error: "city is Required" });
|
return res.status(500).send({ error: "city is Required" });
|
||||||
case !country:
|
case !country:
|
||||||
return res.status(500).send({ error: "country is Required" });
|
return res.status(500).send({ error: "country is Required" });
|
||||||
case !business_name:
|
|
||||||
return res.status(500).send({ error: "business_name is Required" });
|
|
||||||
case !email:
|
case !email:
|
||||||
return res.status(500).send({ error: "email is Required" });
|
return res.status(500).send({ error: "email is Required" });
|
||||||
case !contact_Number:
|
case !contact_Number:
|
||||||
return res.status(500).send({ error: "contact_Number is Required" });
|
return res.status(500).send({ error: "contact_Number is Required" });
|
||||||
case !contact_Person_Name:
|
|
||||||
return res
|
|
||||||
.status(500)
|
|
||||||
.send({ error: "contact_Person_Name is Required" });
|
|
||||||
case !url:
|
|
||||||
return res.status(500).send({ error: " Business url is Required" });
|
|
||||||
case !short_url:
|
case !short_url:
|
||||||
return res.status(500).send({ error: "short_url is Required" });
|
return res.status(500).send({ error: "short_url is Required" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// create unique url from short url and unique slug and add it to req.body
|
||||||
|
const slug = await Business.find({ short_url: req.body?.short_url });
|
||||||
|
const uniqueSlug =
|
||||||
|
slug.length > 0
|
||||||
|
? `${req.body?.short_url}-${slug.length}`
|
||||||
|
: req.body?.short_url;
|
||||||
|
req.body.url = `${url}${uniqueSlug}`;
|
||||||
|
|
||||||
let businesse = await Business.findOne({ email });
|
let businesse = await Business.findOne({ email });
|
||||||
if (businesse) {
|
if (businesse) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
@ -76,13 +74,7 @@ export const createBusiness = async (req, res) => {
|
|||||||
const businessWithURL = await Business.findOne({
|
const businessWithURL = await Business.findOne({
|
||||||
short_url: req.body?.short_url,
|
short_url: req.body?.short_url,
|
||||||
});
|
});
|
||||||
if (businessWithURL?._id) {
|
|
||||||
if (req?.files?.image?.tempFilePath)
|
|
||||||
fs.unlinkSync(image_file?.tempFilePath);
|
|
||||||
return res
|
|
||||||
.status(400)
|
|
||||||
.json({ message: "business URL is not available!" });
|
|
||||||
}
|
|
||||||
if (req?.files?.image?.tempFilePath) {
|
if (req?.files?.image?.tempFilePath) {
|
||||||
const result = await cloudinary.v2.uploader.upload(
|
const result = await cloudinary.v2.uploader.upload(
|
||||||
image_file?.tempFilePath,
|
image_file?.tempFilePath,
|
||||||
|
@ -1,86 +1,75 @@
|
|||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
import validator from "validator"
|
import validator from "validator";
|
||||||
import bcrypt from "bcryptjs"
|
import bcrypt from "bcryptjs";
|
||||||
import jwt from "jsonwebtoken"
|
import jwt from "jsonwebtoken";
|
||||||
import crypto from "crypto"
|
import crypto from "crypto";
|
||||||
const { Schema, model } = mongoose;
|
const { Schema, model } = mongoose;
|
||||||
|
|
||||||
const BusinessSchema = new Schema(
|
const BusinessSchema = new Schema(
|
||||||
{
|
{
|
||||||
|
business: { type: String, required: true },
|
||||||
|
|
||||||
|
specialization: {
|
||||||
business: { type: String, required: true },
|
type: String,
|
||||||
purpose: { type: String, required: true },
|
|
||||||
|
|
||||||
language: [{ type: Array, default: [], required: true }],
|
|
||||||
//contacts
|
|
||||||
business_name: {
|
|
||||||
type: String,
|
|
||||||
required: [true, "Please Enter Your business_name"],
|
|
||||||
maxLength: [50, "business_name cannot exceed 30 characters"],
|
|
||||||
minLength: [3, "business_name should have more than 3 characters"],
|
|
||||||
}, email: {
|
|
||||||
type: String,
|
|
||||||
required: [true, "Please Enter Your Email"],
|
|
||||||
|
|
||||||
unique: [true, "Email already exist ! please try with diffent email"],
|
|
||||||
|
|
||||||
|
|
||||||
validate: [validator.isEmail, "Please Enter a valid Email"],
|
|
||||||
},
|
|
||||||
password: {
|
|
||||||
type: String,
|
|
||||||
required: [true, "Please Enter Your Password"],
|
|
||||||
minLength: [6, "Password should be greater than 6 characters"],
|
|
||||||
select: false,//find not got passpord
|
|
||||||
},
|
|
||||||
|
|
||||||
contact_Number: { type: Number, required: true },
|
|
||||||
contact_Person_Name: { type: String, required: true },
|
|
||||||
|
|
||||||
url: { type: String, default: "" },
|
|
||||||
short_url: { type: String, default: "" },
|
|
||||||
banner: { type: Object, default: { url: "", public_id: "" } },
|
|
||||||
///
|
|
||||||
//address
|
|
||||||
address_Line_1: { type: String, required: true },
|
|
||||||
address_Line_2: { type: String, required: true },
|
|
||||||
country: { type: String, required: true, default: "" },
|
|
||||||
state: { type: String, required: true, default: "" },
|
|
||||||
city: { type: String, required: true },
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pincode: { type: Number, required: true },
|
|
||||||
|
|
||||||
|
|
||||||
added_by: {
|
|
||||||
type: mongoose.Schema.ObjectId,
|
|
||||||
ref: "User",
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{ timestamps: true }
|
|
||||||
|
language: [{ type: Array, default: [], required: true }],
|
||||||
|
//contacts
|
||||||
|
business_name: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
email: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
password: {
|
||||||
|
type: String,
|
||||||
|
required: [true, "Please Enter Your Password"],
|
||||||
|
minLength: [6, "Password should be greater than 6 characters"],
|
||||||
|
select: false, //find not got passpord
|
||||||
|
},
|
||||||
|
|
||||||
|
contact_Number: { type: Number, required: true },
|
||||||
|
contact_Person_Name: { type: String, required: true },
|
||||||
|
|
||||||
|
url: { type: String, default: "" },
|
||||||
|
short_url: { type: String, default: "" },
|
||||||
|
banner: { type: Object, default: { url: "", public_id: "" } },
|
||||||
|
///
|
||||||
|
//address
|
||||||
|
address_Line_1: { type: String, required: true },
|
||||||
|
address_Line_2: { type: String, required: true },
|
||||||
|
country: { type: String, required: true, default: "" },
|
||||||
|
state: { type: String, required: true, default: "" },
|
||||||
|
city: { type: String, required: true },
|
||||||
|
|
||||||
|
pincode: { type: Number, required: true },
|
||||||
|
|
||||||
|
added_by: {
|
||||||
|
type: mongoose.Schema.ObjectId,
|
||||||
|
ref: "User",
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ timestamps: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
BusinessSchema.pre("save", async function (next) {
|
BusinessSchema.pre("save", async function (next) {
|
||||||
if (!this.isModified("password")) {
|
if (!this.isModified("password")) {
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.password = await bcrypt.hash(this.password, 12);
|
this.password = await bcrypt.hash(this.password, 12);
|
||||||
});
|
});
|
||||||
|
|
||||||
// JWT TOKEN
|
// JWT TOKEN
|
||||||
BusinessSchema.methods.getJWTToken = function () {
|
BusinessSchema.methods.getJWTToken = function () {
|
||||||
return jwt.sign({ id: this._id }, process.env.JWT_SECRET);
|
return jwt.sign({ id: this._id }, process.env.JWT_SECRET);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Compare Password
|
// Compare Password
|
||||||
|
|
||||||
BusinessSchema.methods.comparePassword = async function (password) {
|
BusinessSchema.methods.comparePassword = async function (password) {
|
||||||
return await bcrypt.compare(password, this.password);
|
return await bcrypt.compare(password, this.password);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Business = model("Business", BusinessSchema);
|
export const Business = model("Business", BusinessSchema);
|
||||||
|
@ -34,6 +34,12 @@ const daysAvailableSchema = new mongoose.Schema({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const specialistSchema = new mongoose.Schema({
|
const specialistSchema = new mongoose.Schema({
|
||||||
|
HealthCareProviderID: {
|
||||||
|
type: mongoose.Schema.ObjectId,
|
||||||
|
ref: "Businesses",
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
|
||||||
specialistName: {
|
specialistName: {
|
||||||
type: String,
|
type: String,
|
||||||
required: [true, "Please enter specialist name"],
|
required: [true, "Please enter specialist name"],
|
||||||
|
Loading…
Reference in New Issue
Block a user