From 468238a28f227c8a90165933a1e12bc97b1e982b Mon Sep 17 00:00:00 2001 From: vzaisun Date: Tue, 5 Mar 2024 15:12:11 +0530 Subject: [PATCH] seo api added --- app.js | 4 ++ .../ContactRequests/ContactRequestsModel.js | 3 -- resources/SEO&Analytics/SEOController.js | 39 +++++++++++++++++++ resources/SEO&Analytics/SEOModel.js | 33 ++++++++++++++++ resources/SEO&Analytics/SEORouter.js | 12 ++++++ 5 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 resources/SEO&Analytics/SEOController.js create mode 100644 resources/SEO&Analytics/SEOModel.js create mode 100644 resources/SEO&Analytics/SEORouter.js diff --git a/app.js b/app.js index 705bafb..c67ffcc 100644 --- a/app.js +++ b/app.js @@ -157,6 +157,8 @@ import SpecialtiesRouter from "./resources/Specialties/SpecialtiesRoute.js"; import ShippingAddressRoute from "./resources/ShippingAddresses/ShippingAddressRoute.js"; import stripeRoute from "./resources/StripePayment/stripeRoute.js"; +import SeoRoute from "./resources/SEO&Analytics/SEORouter.js" + //short urls // import ShortUrlRouter from "./resources/Businesses/Short_Urls/ShortUrlRoute.js"; @@ -203,6 +205,8 @@ app.use("/api/tax", TaxRouter); app.use("/api/config", ConfigRouter); app.use("/api/stripe",stripeRoute); + +app.use("/api/seo",SeoRoute); //config specialty // app.use("/api/config/specialty", SpecialtiesRouter); //specialties diff --git a/resources/ContactRequests/ContactRequestsModel.js b/resources/ContactRequests/ContactRequestsModel.js index ccad01d..6dcca01 100644 --- a/resources/ContactRequests/ContactRequestsModel.js +++ b/resources/ContactRequests/ContactRequestsModel.js @@ -1,7 +1,4 @@ - - - import mongoose from "mongoose"; const { Schema, model } = mongoose; diff --git a/resources/SEO&Analytics/SEOController.js b/resources/SEO&Analytics/SEOController.js new file mode 100644 index 0000000..8a25cfe --- /dev/null +++ b/resources/SEO&Analytics/SEOController.js @@ -0,0 +1,39 @@ +import {SeoRequest} from "./SEOModel.js"; + +export const AddNewSeoRequest = async (req, res) => { + try { + + let existingSeoRequest = await SeoRequest.findOne(); + + if (existingSeoRequest) { + + existingSeoRequest.GoogleTag = req.body.GoogleTag; + existingSeoRequest.FacebookPixel = req.body.FacebookPixel; + existingSeoRequest.GoogleAnalytics = req.body.GoogleAnalytics; + existingSeoRequest.MicrosoftClarity=req.body.MicrosoftClarity; + + + existingSeoRequest = await existingSeoRequest.save(); + + res.status(200).json({ + success: true, + seorequest: existingSeoRequest, + message: "Seo Request Updated", + }); + } else { + + const newSeoRequest = await SeoRequest.create(req.body); + + res.status(201).json({ + success: true, + seorequest: newSeoRequest, + message: "Seo Request Added", + }); + } + } catch (error) { + res.status(500).json({ + success: false, + message: error.message ? error.message : "Something went Wrong", + }); + } +}; diff --git a/resources/SEO&Analytics/SEOModel.js b/resources/SEO&Analytics/SEOModel.js new file mode 100644 index 0000000..625cb84 --- /dev/null +++ b/resources/SEO&Analytics/SEOModel.js @@ -0,0 +1,33 @@ +import mongoose from "mongoose"; + +const { Schema, model } = mongoose; + +const SeoRequestSchema = new mongoose.Schema( + { + + GoogleTag: { + type: String, + maxLength: [25, "tag cannot exceed 25 characters"], + required: [true, "Please Enter google tag "], + }, + FacebookPixel: { + type: String, + maxLength: [25, "tag cannot exceed 25 characters"], + required: [true, "Please Enter Facebook Pixel "], + }, + GoogleAnalytics: { + type: String, + maxLength: [500, "google analytics cannot exceed 500 characters"], + required: [true, "Please Enter google analytics"], + }, + MicrosoftClarity: { + type: String, + maxLength: [500, "Microsoft clarity cannot exceed 500 characters"], + required: [true, "Please Enter microsoft clarity"], + }, + + }, + { timestamps: true, versionKey: false } +); + +export const SeoRequest = mongoose.model("SeoRequest", SeoRequestSchema); diff --git a/resources/SEO&Analytics/SEORouter.js b/resources/SEO&Analytics/SEORouter.js new file mode 100644 index 0000000..33bf606 --- /dev/null +++ b/resources/SEO&Analytics/SEORouter.js @@ -0,0 +1,12 @@ +import express from "express"; +import { isAuthenticatedUser, authorizeRoles } from "../../middlewares/auth.js"; +import { AddNewSeoRequest } from "./SEOController.js"; + +const router = express.Router(); + +router + .route("/new") + .post(isAuthenticatedUser, authorizeRoles("admin"), AddNewSeoRequest); + + +export default router;