feat: Most of Item and Order controllers
This commit is contained in:
@@ -4,6 +4,24 @@ const CREATE_ORDER = `
|
||||
INSERT INTO order_record(user_id, orderer, date_due, date_placed) VALUES ($1, $2, $3, $4);
|
||||
`
|
||||
|
||||
const GET_ORDER_BY_ORDER_INFORMATION = `
|
||||
SELECT
|
||||
id,
|
||||
user_id,
|
||||
orderer,
|
||||
date_due,
|
||||
date_placed,
|
||||
amount_paid,
|
||||
filled,
|
||||
delivered
|
||||
FROM
|
||||
order_record
|
||||
WHERE
|
||||
user_id = $1
|
||||
AND orderer = $2
|
||||
AND date_placed = $3;
|
||||
`
|
||||
|
||||
const SET_ORDER_FILLED = `
|
||||
UPDATE order_record SET filled = $1 WHERE id = $2
|
||||
`
|
||||
@@ -17,15 +35,23 @@ UPDATE order_record SET amount_paid = $1 WHERE id = $2
|
||||
`
|
||||
|
||||
const GET_ORDER_TOTAL_AND_BALANCE = `
|
||||
SELECT
|
||||
SUM(oi.quantity * iph.price) AS order_total,
|
||||
SELECT
|
||||
orec.id,
|
||||
order_total - orec.amount_paid AS balance
|
||||
FROM
|
||||
order_item oi
|
||||
INNER JOIN item i ON oi.item_id = i.init_db_pool
|
||||
AND oi.order_id = $1
|
||||
INNER JOIN order_record orec ON oi.order_id = orec.order_id
|
||||
INNER JOIN item_price_history iph ON iph.item_id = i.id
|
||||
AND iph.valid_from <= oi.created_at
|
||||
AND (iph.valid_to IS NULL OR iph.valid_to > oi.created_at);
|
||||
order_record orec
|
||||
INNER JOIN (
|
||||
SELECT
|
||||
orec.id,
|
||||
SUM(quantity * price) AS order_total
|
||||
FROM
|
||||
order_record orec
|
||||
INNER JOIN order_item oi ON oi.order_id = orec.id
|
||||
INNER JOIN item i ON oi.item_id = i.id
|
||||
AND oi.order_id = 1
|
||||
INNER JOIN item_price_history iph ON iph.item_id = i.id
|
||||
AND iph.valid_from <= oi.created_at
|
||||
AND (iph.valid_to IS NULL OR iph.valid_to > oi.created_at)
|
||||
GROUP BY orec.id
|
||||
) totals ON orec.id = totals.id
|
||||
`
|
||||
|
||||
Reference in New Issue
Block a user