const mysql = require("mysql2");
const knowledgeQuests = (req, res) => {
    // res.send(req.query.doa); //get
    // res.send(req.body.doa);  //post
    const connection = mysql.createConnection({
      host: process.env.MARIA_HOST,
      user: process.env.MARIA_USER,
      password: process.env.MARIA_PASS,
      database: process.env.MARIA_DBNM
    });
  
      connection.connect((err) => {
        if(err) {
            console.error('Error connecting to the database:', err);
            return;
        }
          console.log('Connected to the MariaDB database.');
      });

      const data = req.body;

      const query = `SELECT * FROM knowledge_quests WHERE status  = 1`;  
      connection.query(query, (err, results) => {
          if (err) {
            console.error('Error inserting data:', err);
            res.status(500).send('Internal Server Error');
            return;
          }
          res.status(200).json(results);
      });
};
  
module.exports = knowledgeQuests;
  


//   let knowledgeData = [
//     {
//       id: "1",
//       status: "1",
//       title: "Assessment on Special Education",
//       challenge: "Challenge yourself & climb the leaderboard.",
//       question: "Subjective Question",
//       img: "/assets/knowledge1.jpg"
//     },
//     {
//       id: "2",
//       status: "1",
//       title: "Quiz on Children Psychology",
//       challenge: "Challenge yourself & climb the leaderboard.",
//       question: "MCQ",
//       img: "/assets/knowledge2.jpg"
//     },
//     {
//       id: "3",
//       status: "1",
//       title: "Quiz on Montessori Methods",
//       challenge: "Challenge yourself & climb the leaderboard.",
//       question: "MCQ",
//       img: "/assets/knowledge3.jpg"
//     }
// ];
// res.json(knowledgeData);