import ServiceRecord from "../models/ServiceRecord.js";
 
export const createServiceRecord = async (req, res) => {
    try {
        const record = await ServiceRecord.create(req.body);
        res.status(201).json(record);
    } catch (error) {
        res.status(500).json({ message: error.message });
    }
};
 
export const getServiceRecord = async (req, res) => {
    try {
        const records = await ServiceRecord.find()
            .populate("car")
            .populate("service");
        res.status(200).json(records);
    } catch (error) {
        res.status(500).json({ message: error.message });
    }
};
 
export const updateServiceRecord = async (req, res) => {
    try {
        const record = await ServiceRecord.findByIdAndUpdate(req.params.id, req.body, { new: true });
        res.status(200).json(record);
    } catch (error) {
        res.status(500).json({ message: error.message });
    }
};
 
export const deleteServiceRecord = async (req, res) => {
    try {
        const record = await ServiceRecord.findByIdAndDelete(req.params.id);
        res.status(200).json(record);
    } catch (error) {
        res.status(500).json({ message: error.message });
    }
};