const mysql = require('mysql2');
const {queryDb} = require("../helpers/db");


const blogHandler = async (req, res) => {
    delete res.locals.offer;
    const slug = mysql.escape(req.params?.slug);
    const query = `SELECT * FROM Blog WHERE slug = ${slug}`
    const offer = await queryDb(query)
    if (!offer?.[0]?.id) {
        res.status(404).render("pages/404View")
        return
    }
    res.locals.offer = offer

    res.render('pages/blogView');
}

module.exports = {
    blogHandler
}