-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0070ead
commit 97081e9
Showing
28 changed files
with
649 additions
and
369 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,6 @@ | |
"trailingComma": "none", | ||
"useTabs": false, | ||
"tabWidth": 2, | ||
"printWidth": 80, | ||
"printWidth": 100, | ||
"semi": true | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,11 +1,10 @@ | ||
import { join } from 'path'; | ||
// APPLICATION | ||
|
||
/** | ||
* The port the application serves HTTP responses on | ||
*/ | ||
export const PORT = process.env.PORT || 3000; | ||
|
||
// PATHS & FILES | ||
export const PROJECT_ROOT = join(__dirname, '..'); | ||
export const PUBLIC_PATH = join(__dirname, 'public'); | ||
|
||
// SQLITE DATABASES | ||
export const MASTER_DB_NAME = 'master.sqlite'; | ||
export const MASTER_DB_FILE = join(PROJECT_ROOT, MASTER_DB_NAME); |
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,61 +1,86 @@ | ||
import { getDb } from '../db/utils'; | ||
import { sql } from '../sql-string'; | ||
|
||
/** | ||
* Get data for the employee sales leaderboard on the dashboard page | ||
*/ | ||
export async function getEmployeeSalesLeaderboard() { | ||
let db = await getDb(); | ||
return await db.all(sql`SELECT (e.firstname || ' ' || e.lastname) as name, sum((od.unitprice * od.quantity))as amount FROM | ||
Employee as e INNER JOIN CustomerOrder as o | ||
ON o.employeeid = e.id | ||
INNER JOIN OrderDetail as od | ||
ON o.id = od.orderid | ||
GROUP BY e.id | ||
ORDER BY amount desc | ||
LIMIT 5 | ||
`); | ||
return await db.all(sql` | ||
SELECT (e.firstname || ' ' || e.lastname) AS name, sum((od.unitprice * od.quantity))as amount | ||
FROM Employee AS e | ||
INNER JOIN CustomerOrder AS o | ||
ON o.employeeid = e.id | ||
INNER JOIN OrderDetail AS od | ||
ON o.id = od.orderid | ||
GROUP BY e.id | ||
ORDER BY amount DESC LIMIT 5`); | ||
} | ||
|
||
/** | ||
* Get data for the customer sales leaderboard on the dashboard page | ||
*/ | ||
export async function getCustomerSalesLeaderboard() { | ||
let db = await getDb(); | ||
return await db.all(sql`SELECT c.companyname as name, sum((od.unitprice * od.quantity))as amount FROM | ||
Customer as c INNER JOIN CustomerOrder as o | ||
ON o.customerid = c.id | ||
INNER JOIN OrderDetail as od | ||
ON o.id = od.orderid | ||
GROUP BY c.id | ||
ORDER BY amount desc | ||
LIMIT 5 | ||
`); | ||
return await db.all(sql` | ||
SELECT c.companyname AS name, | ||
sum((od.unitprice * od.quantity))as amount | ||
FROM Customer AS c | ||
INNER JOIN CustomerOrder AS o | ||
ON o.customerid = c.id | ||
INNER JOIN OrderDetail AS od | ||
ON o.id = od.orderid | ||
GROUP BY c.id | ||
ORDER BY amount DESC LIMIT 5`); | ||
} | ||
|
||
/** | ||
* Get data for the product sales leaderboard on the dashboard page | ||
*/ | ||
export async function getProductSalesLeaderboard() { | ||
let db = await getDb(); | ||
return await db.all(sql`SELECT p.productname as name, sum(od.unitprice * od.quantity) as amount | ||
FROM | ||
OrderDetail AS od | ||
INNER JOIN CustomerOrder AS o ON od.orderid = o.id | ||
INNER JOIN Product AS p ON od.productid = p.id | ||
GROUP BY p.id | ||
ORDER BY amount DESC | ||
LIMIT 5`); | ||
return await db.all(sql` | ||
SELECT p.productname AS name, | ||
sum(od.unitprice * od.quantity) AS amount | ||
FROM OrderDetail AS od | ||
INNER JOIN CustomerOrder AS o | ||
ON od.orderid = o.id | ||
INNER JOIN Product AS p | ||
ON od.productid = p.id | ||
GROUP BY p.id | ||
ORDER BY amount DESC LIMIT 5`); | ||
} | ||
|
||
/** | ||
* Get data for the recent sales list the dashboard page | ||
*/ | ||
export async function getRecentOrders() { | ||
let db = await getDb(); | ||
return await db.all(sql` | ||
SELECT o.id, (e.firstname || ' ' || e.lastname) as employee, c.companyname as customer, o.orderdate, sum(od.unitprice * od.quantity) as subtotal FROM | ||
CustomerOrder as o | ||
INNER JOIN OrderDetail AS od ON od.orderid = o.id | ||
INNER JOIN Employee AS e on o.employeeid = e.id | ||
INNER JOIN Customer AS c on o.customerid = c.id | ||
WHERE o.orderdate IS NOT NULL | ||
GROUP BY o.id, e.firstname, e.lastname, c.companyname | ||
ORDER BY o.orderdate DESC | ||
LIMIT 5`); | ||
SELECT o.id, | ||
(e.firstname || ' ' || e.lastname) AS employee, c.companyname AS customer, o.orderdate, sum(od.unitprice * od.quantity) AS subtotal | ||
FROM CustomerOrder AS o | ||
INNER JOIN OrderDetail AS od | ||
ON od.orderid = o.id | ||
INNER JOIN Employee AS e | ||
ON o.employeeid = e.id | ||
INNER JOIN Customer AS c | ||
ON o.customerid = c.id | ||
WHERE o.orderdate IS NOT NULL | ||
GROUP BY o.id, e.firstname, e.lastname, c.companyname | ||
ORDER BY o.orderdate DESC LIMIT 5`); | ||
} | ||
|
||
/** | ||
* Get data for the reorder list on the dashboard page | ||
*/ | ||
export async function getReorderList() { | ||
let db = await getDb(); | ||
return await db.all( | ||
sql`SELECT productname as name, reorderlevel, unitsinstock, unitsonorder from Product WHERE (unitsinstock + unitsonorder) < reorderlevel` | ||
); | ||
return await db.all(sql` | ||
SELECT productname AS name, | ||
reorderlevel, | ||
unitsinstock, | ||
unitsonorder | ||
FROM Product | ||
WHERE (unitsinstock + unitsonorder) < reorderlevel`); | ||
} |
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
Oops, something went wrong.