// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import { OkPacket, QueryError, RowDataPacket } from "mysql2";
import type { NextApiRequest, NextApiResponse } from 'next';
import { pool } from "../../server/db/connect";

type Data = {
    row: string,
}

const queryString = "SELECT type_pizza.id, type_pizza.title as name, type_pizza.heft_trad, type_pizza.type, type_pizza.heft_thin, type_pizza.price, type_pizza.img_thin, type_pizza.img_trad, type_pizza.size, products.title, products.description FROM type_pizza, products WHERE products.id=type_pizza.id_products and ";

export default function handler(
    req: NextApiRequest,
    res: NextApiResponse<Data>)
    {
        pool.query(
            queryString,
            (err: QueryError, rows: RowDataPacket[0]) => {
                res.status(200).json(rows);
            }
        );
    };