2025-01-27 18:27:13 +00:00
|
|
|
import { PrismaClient } from "@prisma/client";
|
|
|
|
|
|
|
|
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) {
|
2025-01-28 06:31:08 +00:00
|
|
|
res.status(500).json({ status: 500, message: error.message });
|
2025-01-27 18:27:13 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const uploadHeroImages = async (req, res) => {
|
|
|
|
try {
|
|
|
|
const files = req.files;
|
2025-01-28 06:31:08 +00:00
|
|
|
const heroImages = files.map((file) => file.filename);
|
2025-01-27 18:27:13 +00:00
|
|
|
const newHeroImages = await prisma.heroImages.create({
|
2025-01-28 06:31:08 +00:00
|
|
|
data: {
|
|
|
|
urls: heroImages,
|
|
|
|
},
|
2025-01-27 18:27:13 +00:00
|
|
|
});
|
|
|
|
res.status(201).json({ status: 201, data: newHeroImages });
|
|
|
|
} catch (error) {
|
2025-01-28 06:31:08 +00:00
|
|
|
res.status(500).json({ status: 500, message: error.message });
|
2025-01-27 18:27:13 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const updateHeroImage = async (req, res) => {
|
2025-01-28 06:31:08 +00:00
|
|
|
const { id, index } = req.params;
|
2025-01-27 18:27:13 +00:00
|
|
|
try {
|
2025-01-28 06:31:08 +00:00
|
|
|
const data = await prisma.heroImages.findUnique({where:{id: id}})
|
|
|
|
let oldArray = data.urls
|
|
|
|
oldArray[index] = req.file.filename
|
2025-01-27 18:27:13 +00:00
|
|
|
const updatedEvent = await prisma.heroImages.update({
|
|
|
|
where: { id: id },
|
|
|
|
data: {
|
2025-01-28 06:31:08 +00:00
|
|
|
urls: oldArray
|
2025-01-27 18:27:13 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
res.status(200).json({ status: 200, data: updatedEvent });
|
|
|
|
} catch (error) {
|
2025-01-28 06:31:08 +00:00
|
|
|
res.status(500).json({ status: 500, message: error.message });
|
2025-01-27 18:27:13 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const deleteHeroImage = async (req, res) => {
|
|
|
|
const { id } = req.params;
|
|
|
|
try {
|
|
|
|
await prisma.heroImages.delete({
|
|
|
|
where: { id: id },
|
|
|
|
});
|
|
|
|
res.status(200).json({
|
|
|
|
status: 200,
|
2025-01-28 06:31:08 +00:00
|
|
|
message: "Hero Image deleted successfully",
|
2025-01-27 18:27:13 +00:00
|
|
|
});
|
|
|
|
} catch (error) {
|
2025-01-28 06:31:08 +00:00
|
|
|
res.status(500).json({ status: 500, message: error.message });
|
2025-01-27 18:27:13 +00:00
|
|
|
}
|
|
|
|
};
|