import { db } from "@/helpers/api";

export default async function handler(req, res) {
	if (req.method !== "GET") return res.status(405).json({ error: "Method not allowed" });

	if (!db.initialized) await db.initialize();

	const setting = await db.Settings.findOne({ where: { name: "bannerImages" } });
	const allBanners = setting ? JSON.parse(setting.value || "[]") : [];

	const banners = allBanners.filter((b) => b.active);

	return res.status(200).json({ banners });
}
