This commit is contained in:
Aritra Banik 2024-03-24 12:32:39 +05:30
parent 73e690655d
commit 30fef95b94
3 changed files with 29 additions and 2 deletions

BIN
src/a3

Binary file not shown.

View File

@ -57,3 +57,27 @@ proc getUser*(db: DbConn, email, password: string): User =
user.accessLevel = parseInt(row[7]) user.accessLevel = parseInt(row[7])
return user return user
proc getUserOrdersAmount*(db: DbConn, userId: int): (int, int)=
var
row = db.getAllRows(sql"SELECT * FROM orders WHERE user_id=?", userId)
totalQuantity = 0
totalPrice = 0
for b, c in row:
var
quantity = c[8]
row1 = db.getValue(sql"SELECT price FROM products WHERE id=?", c[7])
totalQuantity = parseInt(quantity)
totalPrice = parseInt(row1)
return (totalQuantity, totalPrice)
proc getUserCartTable*(db: DbConn)=
var
row = db.getAllRows(sql"SELECT * FROM users;")
for a, b in row:
var
c = db.getValue(sql"SELECT COUNT(id) FROM orders WHERE user_id=?", b[0])
# d = db.getUserOrdersAmount(parseInt(b[0]))
# d = db.getValue(sql"SELECT SUM()")

View File

@ -1,7 +1,10 @@
import import
mike, mike,
nimja nimja,
./a3pkg/mics
proc admin*(ctx: Context): string= proc admin*(ctx: Context): string=
var
db = newDatabase()
compileTemplateFile(getScriptDir() / "a3a" / "admin" / "index.html") compileTemplateFile(getScriptDir() / "a3a" / "admin" / "index.html")