srl
This commit is contained in:
parent
ac12d5dfd4
commit
258b3e48f1
4
app.js
4
app.js
@ -49,6 +49,8 @@ import SpecialtiesRouter from "./resources/Specialties/SpecialtiesRoute.js";
|
|||||||
import SpecialistRouter from "./resources/Specialist/SpecialistRoute.js";
|
import SpecialistRouter from "./resources/Specialist/SpecialistRoute.js";
|
||||||
//appointments
|
//appointments
|
||||||
import AppointmentRouter from "./resources/Appointments/AppointmentRoute.js";
|
import AppointmentRouter from "./resources/Appointments/AppointmentRoute.js";
|
||||||
|
//short urls
|
||||||
|
import ShortUrlRouter from "./resources/Businesses/Short_Urls/ShortUrlRoute.js";
|
||||||
|
|
||||||
app.use("/api/v1/", user);
|
app.use("/api/v1/", user);
|
||||||
|
|
||||||
@ -84,5 +86,7 @@ app.use("/api/config/specialty", SpecialtiesRouter);
|
|||||||
app.use("/api/specialist", SpecialistRouter);
|
app.use("/api/specialist", SpecialistRouter);
|
||||||
//appointments
|
//appointments
|
||||||
app.use("/api/appointment", AppointmentRouter);
|
app.use("/api/appointment", AppointmentRouter);
|
||||||
|
//short urls
|
||||||
|
app.use("/api/shorturl", ShortUrlRouter);
|
||||||
|
|
||||||
export default app;
|
export default app;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import sendEmail from "../../Utils/sendEmail.js";
|
import sendEmail from "../../Utils/sendEmail.js";
|
||||||
import cloudinary from "../../Utils/cloudinary.js";
|
import cloudinary from "../../Utils/cloudinary.js";
|
||||||
import { Business } from "./BusinessModel.js";
|
import { Business } from "./BusinessModel.js";
|
||||||
|
import { ShortUrl } from "./Short_Urls/ShortUrlModel.js";
|
||||||
import password from "secure-random-password";
|
import password from "secure-random-password";
|
||||||
import bcrypt from "bcryptjs";
|
import bcrypt from "bcryptjs";
|
||||||
|
|
||||||
@ -62,6 +63,7 @@ export const createBusiness = async (req, res) => {
|
|||||||
slug.length > 0
|
slug.length > 0
|
||||||
? `${req.body?.short_url}-${slug.length}`
|
? `${req.body?.short_url}-${slug.length}`
|
||||||
: req.body?.short_url;
|
: req.body?.short_url;
|
||||||
|
req.body.short_url = uniqueSlug;
|
||||||
req.body.url = `${url}${uniqueSlug}`;
|
req.body.url = `${url}${uniqueSlug}`;
|
||||||
|
|
||||||
let businesse = await Business.findOne({ email });
|
let businesse = await Business.findOne({ email });
|
||||||
@ -102,6 +104,10 @@ export const createBusiness = async (req, res) => {
|
|||||||
|
|
||||||
req.body.added_by = req.user._id;
|
req.body.added_by = req.user._id;
|
||||||
const businesses = await Business.create(req.body);
|
const businesses = await Business.create(req.body);
|
||||||
|
const shortUrls = await ShortUrl.create({
|
||||||
|
shortUrl: req.body?.short_url,
|
||||||
|
HealthCareProviderID: businesses._id,
|
||||||
|
});
|
||||||
await sendEmail({
|
await sendEmail({
|
||||||
to: `${req.body.email}`, // Change to your recipient
|
to: `${req.body.email}`, // Change to your recipient
|
||||||
|
|
||||||
@ -162,7 +168,6 @@ export const getBusinessDetails = catchAsyncErrors(async (req, res, next) => {
|
|||||||
|
|
||||||
export const getSingleBusiness = async (req, res) => {
|
export const getSingleBusiness = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
|
||||||
if (!req?.params.id)
|
if (!req?.params.id)
|
||||||
return res.status(400).json({ message: "please Provide Business ID !" });
|
return res.status(400).json({ message: "please Provide Business ID !" });
|
||||||
|
|
||||||
@ -293,13 +298,13 @@ export const deleteBusinessById = async (req, res) => {
|
|||||||
if (!req?.params.id)
|
if (!req?.params.id)
|
||||||
return res.status(400).json({ message: "please Provide Business ID !" });
|
return res.status(400).json({ message: "please Provide Business ID !" });
|
||||||
|
|
||||||
const business = await Business.findByIdAndDelete(req.params.id);
|
const business = await Business.findById(req.params.id);
|
||||||
if (!business) {
|
if (!business) {
|
||||||
return res.status(400).json({ message: "business Not Found" });
|
return res.status(400).json({ message: "business Not Found" });
|
||||||
}
|
}
|
||||||
await business.remove();
|
await business.remove();
|
||||||
|
|
||||||
res.status(200).json({ status: "OK", msg: "Deteted successfully" });
|
res.status(200).json({ status: "OK", msg: "Deleted successfully" });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return res
|
return res
|
||||||
.status(500)
|
.status(500)
|
||||||
|
@ -3,6 +3,9 @@ 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";
|
||||||
|
import { ShortUrl } from "./Short_Urls/ShortUrlModel.js";
|
||||||
|
import { Appointment } from "../Appointments/AppointmentModel.js";
|
||||||
|
import { Specialist } from "../Specialist/SpecialistModel.js";
|
||||||
const { Schema, model } = mongoose;
|
const { Schema, model } = mongoose;
|
||||||
|
|
||||||
const BusinessSchema = new Schema(
|
const BusinessSchema = new Schema(
|
||||||
@ -53,6 +56,26 @@ const BusinessSchema = new Schema(
|
|||||||
{ timestamps: true }
|
{ timestamps: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
BusinessSchema.pre("remove", async function (next) {
|
||||||
|
try {
|
||||||
|
// Delete all the short urls associated with the healthcare provider
|
||||||
|
await ShortUrl.deleteMany({ HealthCareProviderID: this._id });
|
||||||
|
|
||||||
|
// Delete all the appointments associated with the healthcare provider
|
||||||
|
await Appointment.deleteMany({
|
||||||
|
HealthCareProviderID: this._id,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Delete all the specialist associated with the healthcare provider
|
||||||
|
await Specialist.deleteMany({
|
||||||
|
HealthCareProviderID: this._id,
|
||||||
|
});
|
||||||
|
next();
|
||||||
|
} catch (error) {
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
BusinessSchema.pre("save", async function (next) {
|
BusinessSchema.pre("save", async function (next) {
|
||||||
if (!this.isModified("password")) {
|
if (!this.isModified("password")) {
|
||||||
next();
|
next();
|
||||||
|
39
resources/Businesses/Short_Urls/ShortUrlController.js
Normal file
39
resources/Businesses/Short_Urls/ShortUrlController.js
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import { ShortUrl } from "./ShortUrlModel.js";
|
||||||
|
|
||||||
|
// get all short urls
|
||||||
|
export const getAllShortUrls = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const shortUrls = await ShortUrl.find();
|
||||||
|
res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
shortUrls,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
res.status(400).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// get a single short url
|
||||||
|
export const getSingleShortUrl = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const shortUrl = await ShortUrl.findById(req.params.id);
|
||||||
|
if (!shortUrl) {
|
||||||
|
return res.status(404).json({
|
||||||
|
success: false,
|
||||||
|
message: "Short url not found",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
shortUrl,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
res.status(400).json({
|
||||||
|
success: false,
|
||||||
|
message: error.message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
16
resources/Businesses/Short_Urls/ShortUrlModel.js
Normal file
16
resources/Businesses/Short_Urls/ShortUrlModel.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import mongoose from "mongoose";
|
||||||
|
const { Schema, model } = mongoose;
|
||||||
|
|
||||||
|
const ShortUrlSchema = new Schema(
|
||||||
|
{
|
||||||
|
shortUrl: { type: String, required: true },
|
||||||
|
HealthCareProviderID: {
|
||||||
|
type: mongoose.Schema.ObjectId,
|
||||||
|
ref: "Businesses",
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ timestamps: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
export const ShortUrl = model("ShortUrl", ShortUrlSchema);
|
9
resources/Businesses/Short_Urls/ShortUrlRoute.js
Normal file
9
resources/Businesses/Short_Urls/ShortUrlRoute.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { Router } from "express";
|
||||||
|
import { getAllShortUrls, getSingleShortUrl } from "./ShortUrlController.js";
|
||||||
|
|
||||||
|
const router = Router();
|
||||||
|
|
||||||
|
router.route("/getall").get(getAllShortUrls);
|
||||||
|
router.route("/get/:id").get(getSingleShortUrl);
|
||||||
|
|
||||||
|
export default router;
|
Loading…
Reference in New Issue
Block a user