const TraderOnOff = require("../models/TraderOnOff");
const Email = require("../controllers/email");
const bcrypt = require("bcryptjs");
const jwt = require("jsonwebtoken");
const ejs = require("ejs");
const path = require("path");

// @route GET api/user
// @desc Returns all users
// @access Public

exports.ShowHide = async function (req, res) {
    // console.log("nnnnnn", req.body);
    console.log("nnnnnn", req.body.data);
    const body = req.body.data;
    try {
        // Try to find a document that matches certain criteria
        let presentData = await TraderOnOff.find();
        console.log("presentData", presentData.length);
        if(presentData.length === 0){
            const newTrader = new TraderOnOff({TradeShow:body});
            await newTrader.save();
            res.status(200).json({ message: "success", data: newTrader });
        }else{
            presentData[0].TradeShow = body;
            console.log("abc====", presentData)
            const updatedTrader = await presentData[0].save();
            res.status(200).json({ message: "success", data: updatedTrader });
        }
    } catch (error) {
        console.log("is match 1st error===>>>", error);
        res.status(404).json({ success: false, message: error.message });
    }
}



exports.GetShowHide = async function (req, res) {
    console.log("nnnnnn"); 
    try {
         let data = await TraderOnOff.find();
        res.status(200).json({ message: "success", data });
    } catch (error) {
        console.log("is match 1st error===>>>", error);
        res.status(404).json({ success: false, message: error.message });
    }
}



