const mongoose = require("mongoose");

const AdminSchema = new mongoose.Schema(
  {
    username: {
      type: String,
      required: true,
      unique: true,
    },
    password: {
      type: String,
      required: true,
    },
    role: {
      type: String,
      default: "admin",
    },
  },
  { timestamps: true }
);

module.exports = mongoose.model("Admin", AdminSchema);

This is my admin models


const express = require("express");
const router = express.Router();
const bcrypt = require("bcryptjs");
const jwt = require("jsonwebtoken");
const Admin = require("../models/Admin");
const { verifyToken } = require("../middlewares/auth");

// Admin registration (you might want to secure this route or create admins manually)
router.post("/register", async (req, res) => {
  try {
    const { username, password } = req.body;
    const hashedPassword = await bcrypt.hash(password, 10);

    const admin = new Admin({ username, password: hashedPassword });
    await admin.save();

    res.status(201).json({ message: "Admin created successfully" });
  } catch (error) {
    res.status(500).json({ error: "Error creating admin" });
  }
});

// Admin login
router.post("/login", async (req, res) => {
  try {
    const { username, password } = req.body;
    const admin = await Admin.findOne({ username });

    if (!admin) {
      return res.status(400).json({ error: "Admin not found" });
    }

    const validPassword = await bcrypt.compare(password, admin.password);
    if (!validPassword) {
      return res.status(400).json({ error: "Invalid password" });
    }

    const token = jwt.sign(
      { _id: admin._id, role: admin.role },
      process.env.JWT_SECRET,
      { expiresIn: "1h" }
    );
    res.json({ token });
  } catch (error) {
    res.status(500).json({ error: "Login error" });
  }
});

// Protected route example
router.get("/dashboard", verifyToken, (req, res) => {
  res.json({
    message: "Welcome to the admin dashboard",
    adminId: req.admin._id,
  });
});

module.exports = router;

This is my admin controller Now what I want is that admin is able to do everything like have control over all the articles and news one make a admin controller


const Article = require("../models/Article");
const { handleControllerError } = require("../utils/errorHandler");

// Function to handle uploading a new article
const addArticle = async (req, res) => {
  try {
    const { title, content, author } = req.body;
    const headingImage = req.file ? `/uploads/${req.file.filename}` : null;

    if (!title || !content || !author) {
      return res.status(400).json({ message: "All fields are required." });
    }

    const newArticle = new Article({
      title,
      content,
      author,
      headingImage,
    });

    await newArticle.save();

    res
      .status(201)
      .json({
        message: "Article uploaded successfully.",
        articleId: newArticle._id,
      });
  } catch (error) {
    handleControllerError(error, res, "addArticle");
  }
};

// Function to fetch all articles
const getArticles = async (req, res) => {
  try {
    const articles = await Article.find().sort({ createdAt: -1 });
    res.json(articles);
  } catch (error) {
    handleControllerError(error, res, "getArticles");
  }
};

// Function to fetch a single article by ID
const getArticleById = async (req, res) => {
  try {
    const { id } = req.params;
    const article = await Article.findById(id);

    if (!article) {
      return res.status(404).json({ message: "Article not found." });
    }

    res.json(article);
  } catch (error) {
    handleControllerError(error, res, "getArticleById");
  }
};

module.exports = {
  getArticles,
  addArticle,
  getArticleById,
};
ArticleController.js

// controllers/newsController.js

const { getCachedData } = require("../utils/cacheHelper");
const axiosInstance = require("../utils/axiosInstance");

// Centralized Error Handling for Controller
const handleControllerError = (error, res, functionName) => {
  if (error.response) {
    // API responded with a status code outside 2xx
    console.error(
      `Error in ${functionName}: ${error.response.status} - ${JSON.stringify(
        error.response.data
      )}`
    );
    res.status(error.response.status).json({
      message: error.response.data.message || `Error in ${functionName}`,
      details: error.response.data,
    });
  } else if (error.request) {
    // No response received from API
    console.error(`No response received in ${functionName}:`, error.request);
    res.status(503).json({
      message: `No response from Football API during ${functionName}`,
    });
  } else {
    // Other errors
    console.error(`Error in ${functionName}:`, error.message);
    res
      .status(500)
      .json({ message: `Internal server error in ${functionName}` });
  }
};

// Function to fetch top 10 players for a specific club
const getTopPlayersByClub = async (req, res) => {
  const { club } = req.params; // e.g., 'barcelona', 'realmadrid'
  const cacheKey = `top_players_${club.toLowerCase()}`;
  const fetchFn = async () => {
    try {
      const response = await axiosInstance.get(
        `/players/${encodeURIComponent(club.toLowerCase())}`
      );
      // Assuming the API returns an array of player objects
      const topPlayers = response.data.slice(0, 10); // Get top 10 players
      return topPlayers;
    } catch (error) {
      throw error;
    }
  };

  try {
    const topPlayers = await getCachedData(cacheKey, fetchFn);
    res.status(200).json({
      club: club.charAt(0).toUpperCase() + club.slice(1),
      topPlayers,
    });
  } catch (error) {
    handleControllerError(error, res, `getTopPlayersByClub ${club}`);
  }
};

// Existing functions (getAllPlayers, getPlayersTransfers, etc.)

const getAllPlayers = async (req, res) => {
  const cacheKey = "all_players";
  const fetchFn = async () => {
    const response = await axiosInstance.get("/players");
    return response.data; // Assuming it's an array of players
  };

  try {
    const players = await getCachedData(cacheKey, fetchFn);
    res.status(200).json(players);
  } catch (error) {
    handleControllerError(error, res, "getAllPlayers");
  }
};

const getPlayersTransfers = async (req, res) => {
  const cacheKey = "players_transfers";
  const fetchFn = async () => {
    const response = await axiosInstance.get("/players/transfers");
    return response.data; // Assuming it's an array of transfers
  };

  try {
    const transfers = await getCachedData(cacheKey, fetchFn);
    res.status(200).json(transfers);
  } catch (error) {
    handleControllerError(error, res, "getPlayersTransfers");
  }
};

const getPlayersNews = async (req, res) => {
  const cacheKey = "players_news";
  const fetchFn = async () => {
    const response = await axiosInstance.get("/players/news");
    return response.data; // Assuming it's an array of news articles
  };

  try {
    const news = await getCachedData(cacheKey, fetchFn);
    res.status(200).json(news);
  } catch (error) {
    handleControllerError(error, res, "getPlayersNews");
  }
};

const getBettingLaLiga = async (req, res) => {
  const cacheKey = "betting_laliga";
  const fetchFn = async () => {
    const response = await axiosInstance.get("/betting/laliga");
    return response.data; // Assuming it's betting information
  };

  try {
    const laLigaData = await getCachedData(cacheKey, fetchFn);
    res.status(200).json(laLigaData);
  } catch (error) {
    handleControllerError(error, res, "getBettingLaLiga");
  }
};

const getBettingPremierLeague = async (req, res) => {
  const cacheKey = "betting_premierleague";
  const fetchFn = async () => {
    const response = await axiosInstance.get("/betting/premuire-league"); // Fixed endpoint spelling
    return response.data; // Assuming it's betting information
  };

  try {
    const premierLeagueData = await getCachedData(cacheKey, fetchFn);
    res.status(200).json(premierLeagueData);
  } catch (error) {
    handleControllerError(error, res, "getBettingPremierLeague");
  }
};

// ... other functions as needed

module.exports = {
  getAllPlayers,
  getPlayersTransfers,
  getPlayersNews,
  getTopPlayersByClub,
  getBettingLaLiga,
  getBettingPremierLeague,
  // ... other exports
};

You can write news via admin like in frontend I'll open article and news form in which images heading and many things like H3 tag para graph and images + carasoul will be used 
and also have previous which news I'm getting and look into it for images problem I'm not seeing images from API one