 
import Record from "../models/Record.js";
import { json } from "express";

export const createRecord = async (req,res) => {
    try{
    const record = await Record.create(req.body);
    res.status(201).json(record);
    }catch(error){
res.status(500).json({message:error.message});
    }
};

export const getRecord = async (req,res) => {
    try{
        const record = await Record.find()
        .populate({
            path:'payment',
            populate:[
                {path:'student'},
                {path:'fees'}
            ]
        });
            
        res.status(200).json(record);
    }catch(error){
        res.status(500).json({message:error.message});
    }
};

export const updateRecord = async (req,res) => {
    try{
        const record = await Record.findByIdAndUpdate(req.body);
        res.status(200).json(record)
    }catch(error){
        res.status(500).json({message:error.message});
    }
};

export const deleteRecord = async (req,res) => {
    try{
        const record = await Record.findByIdAndDelete(req.body);
        res.status(200).json({message:"record succssfullt deleted"})
    }catch(error){
        res.status(500).json({message:error.message});
    }
};