const ContactMessage = require('../models/ContactMessage'); const { successResponse, errorResponse } = require('../utils/apiResponse'); const submitContactForm = async (req, res, next) => { try { const { name, email, phone, subject, message } = req.body; const msg = await ContactMessage.create({ name, email, phone, subject, message }); return successResponse(res, 'Thank you! Your message has been received.', msg, 201); } catch (error) { next(error); } }; const getContactMessages = async (req, res, next) => { try { const messages = await ContactMessage.find({}).sort({ createdAt: -1 }); return successResponse(res, 'Contact messages retrieved', messages); } catch (error) { next(error); } }; const updateMessageStatus = async (req, res, next) => { try { const msg = await ContactMessage.findByIdAndUpdate(req.params.id, { status: req.body.status }, { new: true }); if (!msg) return errorResponse(res, 'Message not found', [], 404); return successResponse(res, 'Message status updated', msg); } catch (error) { next(error); } }; module.exports = { submitContactForm, getContactMessages, updateMessageStatus };