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


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

    res.render('keyword/keywordDetailsView');
}

module.exports = {
    keywordHandler
}