You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
944 B
27 lines
944 B
// 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);
|
|
}
|
|
);
|
|
};
|
|
|