Compare commits
No commits in common. "bhavnish" and "main" have entirely different histories.
1
client
1
client
|
@ -1 +0,0 @@
|
||||||
Subproject commit c8016b04a9f327f09d0891e7f62d73998d12c25c
|
|
15
server/.env
15
server/.env
|
@ -1,15 +0,0 @@
|
||||||
|
|
||||||
# Environment variables declared in this file are automatically made available to Prisma.
|
|
||||||
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema
|
|
||||||
|
|
||||||
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
|
|
||||||
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
|
|
||||||
|
|
||||||
# DATABASE_URL="mongodb+srv://rishav:rishav123@blog.nnytd.mongodb.net/POC?retryWrites=true&w=majority&appName=Blog"
|
|
||||||
DATABASE_URL = "mongodb+srv://bhavnisharora786:fXcgbSYH0nImdhVT@userdata.qock5.mongodb.net/admin-dashboard?retryWrites=true&w=majority"
|
|
||||||
|
|
||||||
|
|
||||||
# my password
|
|
||||||
# fXcgbSYH0nImdhVT
|
|
||||||
|
|
||||||
PORT=9999
|
|
2
server/.gitignore
vendored
2
server/.gitignore
vendored
|
@ -1,2 +0,0 @@
|
||||||
node_modules
|
|
||||||
# Keep environment variables out of version contro
|
|
|
@ -1,55 +0,0 @@
|
||||||
import { PrismaClient } from "@prisma/client";
|
|
||||||
|
|
||||||
const prisma = new PrismaClient();
|
|
||||||
|
|
||||||
export const getCoaches = async (req, res) => {
|
|
||||||
try {
|
|
||||||
const coaches = await prisma.coach.findMany();
|
|
||||||
res.status(200).json({ status: 200, data: coaches });
|
|
||||||
} catch (error) {
|
|
||||||
res.status(500).json({ status: 500, message: error.message });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const createCoach = async (req, res) => {
|
|
||||||
try {
|
|
||||||
const newEvent = await prisma.coach.create({
|
|
||||||
data: {
|
|
||||||
...req?.body,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
res.status(201).json({ status: 201, data: newEvent });
|
|
||||||
} catch (error) {
|
|
||||||
res.status(500).json({ status: 500, message: error.message });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const updateCoach = async (req, res) => {
|
|
||||||
const { id } = req.params;
|
|
||||||
try {
|
|
||||||
const updatedEvent = await prisma.coach.update({
|
|
||||||
where: { id: id },
|
|
||||||
data: {
|
|
||||||
...req?.body,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
res.status(200).json({ status: 200, data: updatedEvent });
|
|
||||||
} catch (error) {
|
|
||||||
res.status(500).json({ status: 500, message: error.message });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const deleteCoach = async (req, res) => {
|
|
||||||
const { id } = req.params;
|
|
||||||
try {
|
|
||||||
await prisma.coach.delete({
|
|
||||||
where: { id: id },
|
|
||||||
});
|
|
||||||
res.status(200).json({
|
|
||||||
status: 200,
|
|
||||||
message: "Event deleted successfully",
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
res.status(500).json({ status: 500, message: error.message });
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,58 +0,0 @@
|
||||||
import { PrismaClient } from "@prisma/client";
|
|
||||||
|
|
||||||
const prisma = new PrismaClient();
|
|
||||||
|
|
||||||
export const getEvents = async (req, res) => {
|
|
||||||
try {
|
|
||||||
const events = await prisma.events.findMany();
|
|
||||||
res.status(200).json({ status: 200, data: events });
|
|
||||||
} catch (error) {
|
|
||||||
res.status(500).json({ status: 500, message: error.message });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const createEvent = async (req, res) => {
|
|
||||||
const { title, description, date } = req.body;
|
|
||||||
try {
|
|
||||||
const newEvent = await prisma.events.create({
|
|
||||||
data: {
|
|
||||||
title,
|
|
||||||
description,
|
|
||||||
date,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
res.status(201).json({ status: 201, data: newEvent });
|
|
||||||
} catch (error) {
|
|
||||||
res.status(500).json({ status: 500, message: error.message });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const updateEvent = async (req, res) => {
|
|
||||||
const { id } = req.params;
|
|
||||||
try {
|
|
||||||
const updatedEvent = await prisma.events.update({
|
|
||||||
where: { id: id },
|
|
||||||
data: {
|
|
||||||
...req?.body,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
res.status(200).json({ status: 200, data: updatedEvent });
|
|
||||||
} catch (error) {
|
|
||||||
res.status(500).json({ status: 500, message: error.message });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const deleteEvent = async (req, res) => {
|
|
||||||
const { id } = req.params;
|
|
||||||
try {
|
|
||||||
await prisma.events.delete({
|
|
||||||
where: { id: id },
|
|
||||||
});
|
|
||||||
res.status(200).json({
|
|
||||||
status: 200,
|
|
||||||
message: "Event deleted successfully",
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
res.status(500).json({ status: 500, message: error.message });
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,80 +0,0 @@
|
||||||
import { PrismaClient } from "@prisma/client";
|
|
||||||
import CloudinaryUploadHandler from "../utils/CloudinaryClient.js";
|
|
||||||
|
|
||||||
const prisma = new PrismaClient();
|
|
||||||
|
|
||||||
export const getHeroImages = async (req, res) => {
|
|
||||||
try {
|
|
||||||
const coaches = await prisma.heroImages.findMany();
|
|
||||||
res.status(200).json({ status: 200, data: coaches });
|
|
||||||
} catch (error) {
|
|
||||||
res.status(500).json({ status: 500, message: error.message });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const uploadHeroImages = async (req, res) => {
|
|
||||||
try {
|
|
||||||
const files = req.files;
|
|
||||||
const heroImages = files.map((file) => file.filename);
|
|
||||||
const CloudinaryURLs = await heroImages.map((item) =>
|
|
||||||
CloudinaryUploadHandler(`./uploads/${item}`)
|
|
||||||
);
|
|
||||||
Promise.all(CloudinaryURLs)
|
|
||||||
.then(async (results) => {
|
|
||||||
console.log("RTesults: ", results);
|
|
||||||
const newHeroImages = await prisma.heroImages.create({
|
|
||||||
data: {
|
|
||||||
urls: results,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
return res
|
|
||||||
.status(201)
|
|
||||||
.json({ status: 201, data: newHeroImages });
|
|
||||||
})
|
|
||||||
.catch((error) =>
|
|
||||||
res.status(500).json({ status: 500, message: error.message })
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
res.status(500).json({ status: 500, message: error.message });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const updateHeroImage = async (req, res) => {
|
|
||||||
console.log(`req--->`, req);
|
|
||||||
const { id, index } = req.params;
|
|
||||||
try {
|
|
||||||
const data = await prisma.heroImages.findUnique({ where: { id: id } });
|
|
||||||
console.log(`data---->`, data);
|
|
||||||
let dataArray = data.urls;
|
|
||||||
const fileName = req?.file?.filename;
|
|
||||||
const CloudinaryURL = await CloudinaryUploadHandler(
|
|
||||||
`./uploads/${fileName}`
|
|
||||||
);
|
|
||||||
console.log("Cloud", CloudinaryURL);
|
|
||||||
dataArray[index] = CloudinaryURL;
|
|
||||||
const newHeroImages = await prisma.heroImages.update({
|
|
||||||
where: { id },
|
|
||||||
data: {
|
|
||||||
urls: dataArray,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
return res.status(200).json({ status: 200, data: newHeroImages });
|
|
||||||
} catch (error) {
|
|
||||||
res.status(500).json({ status: 500, message: error.message });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const deleteHeroImage = async (req, res) => {
|
|
||||||
const { id } = req.params;
|
|
||||||
try {
|
|
||||||
await prisma.heroImages.delete({
|
|
||||||
where: { id: id },
|
|
||||||
});
|
|
||||||
res.status(200).json({
|
|
||||||
status: 200,
|
|
||||||
message: "Hero Image deleted successfully",
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
res.status(500).json({ status: 500, message: error.message });
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,27 +0,0 @@
|
||||||
config();
|
|
||||||
import { config } from "dotenv";
|
|
||||||
import express from "express";
|
|
||||||
import cors from "cors";
|
|
||||||
|
|
||||||
import EventRouter from "./routes/Event.route.js";
|
|
||||||
import CoachRouter from "./routes/Coach.route.js";
|
|
||||||
import HeroImageRouter from "./routes/HeroImage.route.js";
|
|
||||||
|
|
||||||
const PORT = process.env.PORT;
|
|
||||||
|
|
||||||
const app = express();
|
|
||||||
|
|
||||||
app.use(express.json());
|
|
||||||
app.use(express.urlencoded({ extended: true }));
|
|
||||||
app.use(cors());
|
|
||||||
|
|
||||||
// Test endpoint
|
|
||||||
app.get("/api", (req, res) =>
|
|
||||||
res.status(200).json({ message: "API is working!" })
|
|
||||||
);
|
|
||||||
|
|
||||||
app.use("/api/coach", CoachRouter);
|
|
||||||
app.use("/api/event", EventRouter);
|
|
||||||
app.use("/api/hero-image", HeroImageRouter);
|
|
||||||
|
|
||||||
app.listen(PORT, () => console.log(`Server started on port = ${PORT}`));
|
|
1158
server/package-lock.json
generated
1158
server/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -1,17 +0,0 @@
|
||||||
{
|
|
||||||
"name": "poc-backend",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"type": "module",
|
|
||||||
"scripts": {
|
|
||||||
"dev": "nodemon index.js"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@prisma/client": "^6.2.1",
|
|
||||||
"cloudinary": "^2.5.1",
|
|
||||||
"cors": "^2.8.5",
|
|
||||||
"dotenv": "^16.4.7",
|
|
||||||
"express": "^4.21.2",
|
|
||||||
"multer": "^1.4.5-lts.1",
|
|
||||||
"prisma": "^6.2.1"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,38 +0,0 @@
|
||||||
// This is your Prisma schema file,
|
|
||||||
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
|
||||||
|
|
||||||
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
|
|
||||||
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
|
|
||||||
|
|
||||||
generator client {
|
|
||||||
provider = "prisma-client-js"
|
|
||||||
}
|
|
||||||
|
|
||||||
datasource db {
|
|
||||||
provider = "mongodb"
|
|
||||||
url = env("DATABASE_URL")
|
|
||||||
}
|
|
||||||
|
|
||||||
model HeroImages {
|
|
||||||
id String @id @default(auto()) @map("_id") @db.ObjectId
|
|
||||||
urls String[]
|
|
||||||
createdAt DateTime @default(now())
|
|
||||||
updatedAt DateTime @updatedAt
|
|
||||||
}
|
|
||||||
|
|
||||||
model Coach {
|
|
||||||
id String @id @default(auto()) @map("_id") @db.ObjectId
|
|
||||||
name String
|
|
||||||
title String
|
|
||||||
createdAt DateTime @default(now())
|
|
||||||
updatedAt DateTime @updatedAt
|
|
||||||
}
|
|
||||||
|
|
||||||
model Events {
|
|
||||||
id String @id @default(auto()) @map("_id") @db.ObjectId
|
|
||||||
title String
|
|
||||||
description String
|
|
||||||
date DateTime
|
|
||||||
createdAt DateTime @default(now())
|
|
||||||
updatedAt DateTime @updatedAt
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
import express from "express";
|
|
||||||
|
|
||||||
import {
|
|
||||||
getCoaches,
|
|
||||||
createCoach,
|
|
||||||
updateCoach,
|
|
||||||
deleteCoach,
|
|
||||||
} from "../controllers/Coach.controller.js";
|
|
||||||
|
|
||||||
const CoachRouter = express.Router();
|
|
||||||
|
|
||||||
CoachRouter.get("/", getCoaches)
|
|
||||||
.post("/", createCoach)
|
|
||||||
.put("/:id", updateCoach)
|
|
||||||
.delete("/:id", deleteCoach);
|
|
||||||
|
|
||||||
export default CoachRouter;
|
|
|
@ -1,17 +0,0 @@
|
||||||
import express from "express";
|
|
||||||
|
|
||||||
import {
|
|
||||||
getEvents,
|
|
||||||
createEvent,
|
|
||||||
updateEvent,
|
|
||||||
deleteEvent,
|
|
||||||
} from "../controllers/Event.controller.js";
|
|
||||||
|
|
||||||
const EventRouter = express.Router();
|
|
||||||
|
|
||||||
EventRouter.get("/", getEvents)
|
|
||||||
.post("/", createEvent)
|
|
||||||
.put("/:id", updateEvent)
|
|
||||||
.delete("/:id", deleteEvent);
|
|
||||||
|
|
||||||
export default EventRouter;
|
|
|
@ -1,18 +0,0 @@
|
||||||
import express from "express";
|
|
||||||
import MulterClient from "../utils/multer.js";
|
|
||||||
|
|
||||||
import {
|
|
||||||
getHeroImages,
|
|
||||||
uploadHeroImages,
|
|
||||||
updateHeroImage,
|
|
||||||
deleteHeroImage,
|
|
||||||
} from "../controllers/HeroImage.controller.js";
|
|
||||||
|
|
||||||
const HeroImageRouter = express.Router();
|
|
||||||
|
|
||||||
HeroImageRouter.get("/", getHeroImages)
|
|
||||||
.post("/upload", MulterClient.array("heroImages", 10), uploadHeroImages)
|
|
||||||
.put("/:id/:index", MulterClient.single("heroImages"), updateHeroImage)
|
|
||||||
.delete("/:id", deleteHeroImage);
|
|
||||||
|
|
||||||
export default HeroImageRouter;
|
|
|
@ -1,38 +0,0 @@
|
||||||
import { v2 as cloudinary } from "cloudinary";
|
|
||||||
|
|
||||||
cloudinary.config({
|
|
||||||
cloud_name: "ds6sqynn2",
|
|
||||||
api_key: "814617551846369",
|
|
||||||
api_secret: "Gx3rvuiGhNDRIu9qBnBvyzM6eew", // Click 'View API Keys' above to copy your API secret
|
|
||||||
});
|
|
||||||
|
|
||||||
// // Upload an image
|
|
||||||
// const uploadResult = await cloudinary.uploader
|
|
||||||
// .upload(
|
|
||||||
// "https://res.cloudinary.com/demo/image/upload/getting-started/shoes.jpg",
|
|
||||||
// {
|
|
||||||
// public_id: "shoesByRIshav",
|
|
||||||
// }
|
|
||||||
// )
|
|
||||||
// .catch((error) => {
|
|
||||||
// console.log(error);
|
|
||||||
// });
|
|
||||||
|
|
||||||
// console.log(uploadResult);
|
|
||||||
// console.log(optimizeUrl);
|
|
||||||
|
|
||||||
export default async function CloudinaryUploadHandler(imagePath) {
|
|
||||||
const options = {
|
|
||||||
use_filename: true,
|
|
||||||
unique_filename: false,
|
|
||||||
overwrite: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
const result = await cloudinary.uploader.upload(imagePath, options);
|
|
||||||
console.log(result.secure_url)
|
|
||||||
return result.secure_url;
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
import multer from "multer";
|
|
||||||
|
|
||||||
|
|
||||||
const storage = multer.diskStorage({
|
|
||||||
destination: function (req, file, cb) {
|
|
||||||
cb(null, "./uploads");
|
|
||||||
},
|
|
||||||
filename: function (req, file, cb) {
|
|
||||||
cb(null, (Date.now() + "-" + file.originalname).replaceAll(' ','-'));
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const MulterClient = multer({ storage: storage });
|
|
||||||
|
|
||||||
export default MulterClient;
|
|
Loading…
Reference in a new issue