100
This commit is contained in:
parent
53dfa0f257
commit
fd4d6df422
BIN
db5.sqlite3
BIN
db5.sqlite3
Binary file not shown.
@ -1,6 +1,9 @@
|
||||
import db_connector/db_sqlite
|
||||
|
||||
import ../a3pkg/models
|
||||
import
|
||||
strutils,
|
||||
../a3pkg/models,
|
||||
./users
|
||||
|
||||
proc close*(db: DbConn) =
|
||||
db.close()
|
||||
@ -31,3 +34,24 @@ proc createOrder*(db: DbConn, order:Orders): int64 =
|
||||
|
||||
proc drop*(db: DbConn) =
|
||||
db.exec(sql"DROP TABLE IF EXISTS orders")
|
||||
|
||||
proc getOrderAdmin*(db: DbConn): seq[User]=
|
||||
var
|
||||
row = db.getAllRows(sql"SELECT DISTINCT user_id FROM orders;")
|
||||
users: seq[User]
|
||||
for a, b in row:
|
||||
var
|
||||
u = db.getRow(sql"SELECT * FROM users WHERE id=?", b[0])
|
||||
user: User
|
||||
c = db.getUserOrdersAmount(parseInt(b[0]))
|
||||
|
||||
user.id = parseInt(u[0])
|
||||
user.firstName = u[1]
|
||||
user.lastName = u[2]
|
||||
user.email = u[3]
|
||||
user.totalQuantity = c[0]
|
||||
user.totalPrice = c[1]
|
||||
|
||||
users.add(user)
|
||||
|
||||
return users
|
||||
|
@ -58,20 +58,20 @@ proc getUser*(db: DbConn, email, password: string): User =
|
||||
|
||||
return user
|
||||
|
||||
proc getUserOrdersAmount*(db: DbConn, userId: int): (int, int)=
|
||||
proc getUserOrdersAmount*(db: DbConn, userId: int): (int, float)=
|
||||
echo userId
|
||||
var
|
||||
row = db.getAllRows(sql"SELECT (product_id, quantity) FROM orders WHERE user_id=?", userId)
|
||||
row = db.getAllRows(sql"SELECT * FROM orders WHERE user_id=?", userId)
|
||||
totalQuantity = 0
|
||||
totalPrice = 0
|
||||
totalPrice = 0.0
|
||||
echo row
|
||||
for b, c in row:
|
||||
var
|
||||
quantity = c[1]
|
||||
row1 = db.getValue(sql"SELECT price FROM products WHERE id=?", c[0])
|
||||
quantity = c[8]
|
||||
row1 = db.getValue(sql"SELECT price FROM products WHERE id=?", c[7])
|
||||
|
||||
totalQuantity = totalQuantity + parseInt(quantity)
|
||||
totalPrice = totalPrice + parseInt(quantity) * parseInt(row1)
|
||||
totalPrice = totalPrice + parseFloat(quantity) * parseFloat(row1)
|
||||
return (totalQuantity, totalPrice)
|
||||
|
||||
proc getUserCartTable*(db: DbConn): seq[User]=
|
||||
|
@ -12,7 +12,7 @@ type
|
||||
updatedAt*: DateTime
|
||||
accessLevel*: int
|
||||
totalQuantity*: int
|
||||
totalPrice* :int
|
||||
totalPrice* : float
|
||||
|
||||
Products* = object
|
||||
## Product is the product model
|
||||
|
@ -2,13 +2,17 @@ import
|
||||
mike,
|
||||
nimja,
|
||||
./a3pkg/mics,
|
||||
./a3c/users
|
||||
./a3c/[users, orders]
|
||||
|
||||
proc admin*(ctx: Context): string=
|
||||
var
|
||||
db = newDatabase()
|
||||
users = db.getUserCartTable()
|
||||
users = db.getOrderAdmin()
|
||||
# users = db.getUserCartTable()
|
||||
|
||||
echo users
|
||||
# echov v
|
||||
# var users = db.getUserCartTable()
|
||||
|
||||
# echo users
|
||||
|
||||
compileTemplateFile(getScriptDir() / "a3a" / "admin" / "index.html")
|
||||
|
Loading…
Reference in New Issue
Block a user