import Blog from "./BlogModel.js"; export const createBlog = async (req, res) => { const { title, tags, image, blog_content } = req.body; console.log(req.body); // Checking Fields if (!title || !tags || !image || !blog_content) { return res.status(400).json({ success: false, message: "All fields are mandatory", }); } try { let images = []; let Allfiles = req.files.image; console.log(Allfiles); // if (!Array.isArray(Allfiles)) { // Allfiles = [Allfiles]; // Convert to array if it's not already // } // Allfiles.forEach((file) => { // if (typeof file.tempFilePath === "string") { // let filepath = file.tempFilePath; // images.push(filepath); // } // }); // const newBlog = await Blog.create({ // title, // tags, // image: images, // Assign the array of image file paths // blog_content, // }); res.status(201).json({ success: true, message: "Blog created successfully", data: images, }); } catch (error) { console.error("Error creating blog:", error); res.status(500).json({ success: false, message: error.message ? error.message : "Internal server error", }); } }; export const getAllBlog = async (req, res) => { try { const saveData = await Blog.find(); res.status(200).json({ success: true, message: saveData, }); } catch { res.status(500).json({ success: false, message: "Internal server error", }); } };