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

type Data = {
    QueryError: string,
    RowDataPacket: string
}

export const create = (order: BasicOrder, callback: Function) => {
    const queryString = "SELECT * FROM products"

    db.query(
      queryString,
      [order.product.id, order.customer.id, order.productQuantity],
      (err, result) => {
        if (err) {callback(err)};

        const insertId = (<OkPacket> result).insertId;
        callback(null, insertId);
        console.log(result);
      }
    );
  };
