// 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";

const queryString = "INSERT INTO ProductOrder (product_id, customer_id, product_quantity) VALUES (?, ?, ?)"

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

export const create = (order: BasicOrder, callback: Function) => {
    const queryString = "INSERT INTO ProductOrder (product_id, customer_id, product_quantity) VALUES (?, ?, ?)"
  
    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);
      }
    );
  };
