diff --git a/client/src/pages/Sponsors.tsx b/client/src/pages/Sponsors.tsx index 63d481c..acaa788 100644 --- a/client/src/pages/Sponsors.tsx +++ b/client/src/pages/Sponsors.tsx @@ -1,32 +1,25 @@ import { useEffect, useState } from "react"; import SponsorCard from "../components/SponsorCard"; -import sponsorsJsonData from "../placeholders/sponsors.json"; -// 1. Define the shape of a single sponsor interface Sponsor { name: string; deal: string; address: string; + category: "cbd" | "newmarket" | "other"; code?: string; } -// 2. Define the shape of the whole JSON file -interface SponsorsData { - cbd_sponsors: Sponsor[]; - newmarket_sponsors: Sponsor[]; - other_sponsors: Sponsor[]; -} - const Sponsors = () => { - const [sponsors, setSponsors] = useState(null); + const [sponsors, setSponsors] = useState([]); useEffect(() => { - Promise.resolve(sponsorsJsonData as SponsorsData) + fetch("http://localhost:3000/api/sponsors") + .then((res) => res.json()) .then((data) => setSponsors(data)) .catch((err) => console.error("Error loading sponsors:", err)); }, []); - if (!sponsors) { + if (sponsors.length === 0) { return (
Loading Sponsors... @@ -42,6 +35,10 @@ const Sponsors = () => { padding: "2rem", } as const; + const cbd = sponsors.filter((s) => s.category === "cbd"); + const newmarket = sponsors.filter((s) => s.category === "newmarket"); + const other = sponsors.filter((s) => s.category === "other"); + return (
{/* HERO SECTION */} @@ -71,12 +68,12 @@ const Sponsors = () => {

CBD Sponsors

- {sponsors.cbd_sponsors.map((s, index) => ( + {cbd.map((s, index) => ( ))}
@@ -86,7 +83,7 @@ const Sponsors = () => {

Newmarket Sponsors

- {sponsors.newmarket_sponsors.map((s, index) => ( + {newmarket.map((s, index) => ( {

Other Sponsors

- {sponsors.other_sponsors.map((s, index) => ( + {other.map((s, index) => ( =18.0.0" @@ -2806,13 +2806,13 @@ } }, "node_modules/mongodb": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-7.0.0.tgz", - "integrity": "sha512-vG/A5cQrvGGvZm2mTnCSz1LUcbOPl83hfB6bxULKQ8oFZauyox/2xbZOoGNl+64m8VBrETkdGCDBdOsCr3F3jg==", + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-7.2.0.tgz", + "integrity": "sha512-F/2+BMZtLVhY30ioZp0dAmZ+IRZMBqI+nrv6t5+9/1AIwCa8sMRC3jBf81lpxMhnZgqq8CoUD503Z1oZWq1/sw==", "license": "Apache-2.0", "dependencies": { "@mongodb-js/saslprep": "^1.3.0", - "bson": "^7.0.0", + "bson": "^7.2.0", "mongodb-connection-string-url": "^7.0.0" }, "engines": { @@ -2865,13 +2865,13 @@ } }, "node_modules/mongoose": { - "version": "9.2.4", - "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-9.2.4.tgz", - "integrity": "sha512-XNh+jiztVMddDFDCv8TWxVxi/rGx+0FfsK3Ftj6hcYzEmhTcos2uC144OJRmUFPHSu3hJr6Pgip++Ab2+Da35Q==", + "version": "9.6.1", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-9.6.1.tgz", + "integrity": "sha512-3T8/b0plM3ZJPW3WjlzVMIGJEYYTjgDPQ05Qzru3xu3/wOPSFKWYxdwUF2dl8h3NG5dVkzIuOkZdLacnlLf/sA==", "license": "MIT", "dependencies": { - "kareem": "3.2.0", - "mongodb": "~7.0", + "kareem": "3.3.0", + "mongodb": "~7.2", "mpath": "0.9.0", "mquery": "6.0.0", "ms": "2.1.3", diff --git a/server/package.json b/server/package.json index c7764c9..7d4b874 100644 --- a/server/package.json +++ b/server/package.json @@ -20,7 +20,7 @@ "dotenv": "^17.3.1", "express": "^5.2.1", "express-session": "^1.19.0", - "mongoose": "^9.2.4", + "mongoose": "^9.6.1", "multer": "^2.1.1", "passport": "^0.7.0", "passport-google-oauth20": "^2.0.0" diff --git a/server/src/index.ts b/server/src/index.ts index d0f704f..bfd79c4 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -7,6 +7,7 @@ import { Strategy as GoogleStrategy } from "passport-google-oauth20"; import authRoutes from "./routes/authRoutes"; import imageRoutes from "./routes/imageRoutes"; import executivesRoutes from "./routes/executivesRoutes"; +import sponsorRoutes from "./routes/sponsorRoutes"; // app config dotenv.config({ quiet: true }); @@ -47,6 +48,7 @@ app.use(express.json()); app.use("/api/auth", authRoutes); app.use("/api/images", imageRoutes); app.use("/api/executives", executivesRoutes); +app.use("/api/sponsors", sponsorRoutes); // Connect to MongoDB and start the server mongoose diff --git a/server/src/model/sponsors.ts b/server/src/model/sponsors.ts new file mode 100644 index 0000000..6c54bb3 --- /dev/null +++ b/server/src/model/sponsors.ts @@ -0,0 +1,12 @@ +import mongoose from "mongoose"; + +const sponsorSchema = new mongoose.Schema( + { + name: { type: String, required: true }, + tier: { type: String, enum: ["gold", "silver", "bronze"], required: true }, + logoUrl: { type: String, required: true }, + }, + { timestamps: true } +); + +export const Sponsor = mongoose.model("Sponsor", sponsorSchema); diff --git a/server/src/routes/sponsorRoutes.ts b/server/src/routes/sponsorRoutes.ts new file mode 100644 index 0000000..403ffc1 --- /dev/null +++ b/server/src/routes/sponsorRoutes.ts @@ -0,0 +1,28 @@ +import express from "express"; +import { Sponsor } from "../model/sponsors"; + +const router = express.Router(); + +router.post("/", async (req, res) => { + const sponsor = await Sponsor.create(req.body); + res.json(sponsor); +}); + +router.get("/", async (req, res) => { + const sponsors = await Sponsor.find(); + res.json(sponsors); +}); + +router.put("/:id", async (req, res) => { + const updated = await Sponsor.findByIdAndUpdate(req.params.id, req.body, { + new: true, + }); + res.json(updated); +}); + +router.delete("/:id", async (req, res) => { + await Sponsor.findByIdAndDelete(req.params.id); + res.json({ message: "Deleted" }); +}); + +export default router;