-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat dynamic route customer reporter
- Loading branch information
1 parent
b257a5b
commit 1f2f130
Showing
7 changed files
with
255 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,63 @@ | ||
const useHandingOrdersService = function () { | ||
import styled from "@emotion/styled"; | ||
import { useEffect, useState } from "react"; | ||
|
||
const orders = []; | ||
orders.push({ | ||
no: "1234", | ||
name: "david", | ||
quantity: 2, | ||
price: 87 | ||
}) | ||
orders.push({ | ||
no: "123", | ||
name: "david", | ||
quantity: 2, | ||
price: 87 | ||
}) | ||
orders.push({ | ||
no: "12", | ||
name: "david", | ||
quantity: 2, | ||
price: 87 | ||
}) | ||
orders.push({ | ||
no: "1", | ||
name: "david", | ||
quantity: 2, | ||
price: 87 | ||
}) | ||
return { orders }; | ||
const useHandingOrdersService = function (userId) { | ||
const [orders, setOrders] = useState([]); | ||
useEffect(() => { | ||
if(userId == undefined) return; | ||
//const sqlQuery = `SELECT * FROM orders where customer_id = '${userId}'`; | ||
//console.log(sqlQuery); | ||
//const url = `http://220.135.101.179/query?sql=${escape(sqlQuery)}`; | ||
|
||
// const url = 'http://220.135.101.179/query?sql=' + escape(`\ | ||
// SELECT products.* | ||
// FROM products | ||
// LEFT JOIN order_products | ||
// ON order_products.product_id = products.id | ||
// LEFT JOIN orders | ||
// ON orders.id = order_products.order_id | ||
// WHERE orders.customer_id = 'b6b60fbf-82be-44fc-9099-b72e9e26c812'`); | ||
|
||
const url = `http://220.135.101.179/query?sql= | ||
SELECT * FROM products | ||
INNER JOIN order_products ON order_products.product_id = products.id | ||
INNER JOIN orders | ||
ON orders.id = order_products.order_id | ||
WHERE orders.customer_id = '${userId}' | ||
ORDER BY created_at | ||
` | ||
//console.log(url) | ||
fetch(url) | ||
.then((response) => response.json()) | ||
.then((orders) => setOrders(orders)); | ||
}, [userId]); | ||
return(orders) | ||
// const orders = []; | ||
// orders.push({ | ||
// no: "1234", | ||
// name: "david", | ||
// quantity: 2, | ||
// price: 87 | ||
// }) | ||
// orders.push({ | ||
// no: "123", | ||
// name: "david", | ||
// quantity: 2, | ||
// price: 87 | ||
// }) | ||
// orders.push({ | ||
// no: "12", | ||
// name: "david", | ||
// quantity: 2, | ||
// price: 87 | ||
// }) | ||
// orders.push({ | ||
// no: "1", | ||
// name: "david", | ||
// quantity: 2, | ||
// price: 87 | ||
// }) | ||
// return { orders }; | ||
}; | ||
|
||
export default useHandingOrdersService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,66 @@ | ||
const useMainIncomeService = function () { | ||
const orders = []; | ||
orders.push({ | ||
no: "1234", | ||
name: "david", | ||
quantity: 2, | ||
price: 87 | ||
}) | ||
orders.push({ | ||
no: "1234", | ||
name: "david", | ||
quantity: 2, | ||
price: 87 | ||
}) | ||
orders.push({ | ||
no: "1234", | ||
name: "david", | ||
quantity: 2, | ||
price: 87 | ||
}) | ||
orders.push({ | ||
no: "1234", | ||
name: "david", | ||
quantity: 2, | ||
price: 87 | ||
}) | ||
return { orders }; | ||
}; | ||
import { useEffect, useState } from "react"; | ||
|
||
const useMainIncomeService = function (userId) { | ||
const [orders, setOrders] = useState([]); | ||
useEffect(() => { | ||
if(userId == undefined) return; | ||
//const sqlQuery = `SELECT * FROM orders where customer_id = '${userId}'`; | ||
//console.log(sqlQuery); | ||
//const url = `http://220.135.101.179/query?sql=${escape(sqlQuery)}`; | ||
|
||
// const url = 'http://220.135.101.179/query?sql=' + escape(`\ | ||
// SELECT products.* | ||
// FROM products | ||
// LEFT JOIN order_products | ||
// ON order_products.product_id = products.id | ||
// LEFT JOIN orders | ||
// ON orders.id = order_products.order_id | ||
// WHERE orders.customer_id = 'b6b60fbf-82be-44fc-9099-b72e9e26c812'`); | ||
|
||
const url = `http://220.135.101.179/query?sql= | ||
SELECT products.name as name, sum(price) as price FROM products | ||
INNER JOIN order_products ON order_products.product_id = products.id | ||
INNER JOIN orders | ||
ON orders.id = order_products.order_id | ||
WHERE orders.customer_id = '${userId}' | ||
GROUP BY products.id | ||
ORDER BY price DESC | ||
` | ||
//console.log(url) | ||
fetch(url) | ||
.then((response) => response.json()) | ||
.then((orders) => setOrders(orders)); | ||
}, [userId]); | ||
return(orders) | ||
// const orders = []; | ||
// orders.push({ | ||
// no: "1234", | ||
// name: "david", | ||
// quantity: 2, | ||
// price: 87 | ||
// }) | ||
// orders.push({ | ||
// no: "1234", | ||
// name: "david", | ||
// quantity: 2, | ||
// price: 87 | ||
// }) | ||
// orders.push({ | ||
// no: "1234", | ||
// name: "david", | ||
// quantity: 2, | ||
// price: 87 | ||
// }) | ||
// orders.push({ | ||
// no: "1234", | ||
// name: "david", | ||
// quantity: 2, | ||
// price: 87 | ||
// }) | ||
// return { orders }; | ||
}; | ||
|
||
export default useHandingOrdersService; | ||
export default useMainIncomeService; | ||
|
||
|
Oops, something went wrong.