seo api added

This commit is contained in:
vzaisun 2024-03-05 15:12:11 +05:30
parent fa76a3e0ab
commit 468238a28f
5 changed files with 88 additions and 3 deletions

4
app.js
View File

@ -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

View File

@ -1,7 +1,4 @@
import mongoose from "mongoose";
const { Schema, model } = mongoose;

View File

@ -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",
});
}
};

View File

@ -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);

View File

@ -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;