const mysql = require("mysql2");

const newQuiz = (req, res) => {
    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 = `INSERT INTO quiz (moduleName, type) VALUES (?, ?)`;
    const values = [data.moduleName, data.moduleType];

    connection.query(query, values, (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 = newQuiz
;