Untitled

 avatar
unknown
plain_text
a year ago
741 B
5
Indexable
const insertNewSale = async (timeAdded) => {
  const [createdSale] = await connection.execute(
    'INSERT INTO sales (date) VALUES (?)',
    [timeAdded],
  );
  return createdSale;
};

const insertProductIntoSale = async (nextID, createdSale) => {
  if (createdSale) {
    const SQLquery = createdSale.map((sale) => {
      const { productId, quantity } = sale;
      return connection.execute(
        `INSERT INTO sales_products (sale_id, product_id, quantity)
        VALUES (?, ?, ?)`,
        [nextID, productId, quantity],
      );
    });
    const addedSale = await Promise.all(SQLquery);
    return addedSale;
  }
};

// ESSAS SAO AS EXPORTAÇÕES KRLLLLLLLLLLLLLLLLLLLLL
  findSaleById,  
  insertNewSale,
  insertProductIntoSale,
Editor is loading...
Leave a Comment