diff --git a/src/a3a/admin/index.html b/src/a3a/admin/index.html
index 697cc5d..7abacbc 100644
--- a/src/a3a/admin/index.html
+++ b/src/a3a/admin/index.html
@@ -514,9 +514,9 @@
User |
Last name |
+ Email |
Orders |
Amount |
- Email |
diff --git a/src/a3c/users.nim b/src/a3c/users.nim
index 04bc4aa..a7878c3 100644
--- a/src/a3c/users.nim
+++ b/src/a3c/users.nim
@@ -60,24 +60,35 @@ proc getUser*(db: DbConn, email, password: string): User =
proc getUserOrdersAmount*(db: DbConn, userId: int): (int, int)=
var
- row = db.getAllRows(sql"SELECT * FROM orders WHERE user_id=?", userId)
+ row = db.getAllRows(sql"SELECT product_id, quantity 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])
+ quantity = c[1]
+ row1 = db.getValue(sql"SELECT price FROM products WHERE id=?", c[0])
- totalQuantity = parseInt(quantity)
- totalPrice = parseInt(row1)
+ totalQuantity = totalQuantity + parseInt(quantity)
+ totalPrice = totalPrice + parseInt(quantity) * parseInt(row1)
return (totalQuantity, totalPrice)
-proc getUserCartTable*(db: DbConn)=
+proc getUserCartTable*(db: DbConn): seq[User]=
var
row = db.getAllRows(sql"SELECT * FROM users;")
+ users: seq[User]
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()")
+ c = db.getUserOrdersAmount(parseInt(b[0]))
+ user: User
+
+ user.id = parseInt(b[0])
+ user.firstName = b[1]
+ user.lastName = b[2]
+ user.email = b[3]
+ user.totalQuantity = c[0]
+ user.totalPrice = c[1]
+
+ users.add(user)
+
+ return users
diff --git a/src/a3pkg/models.nim b/src/a3pkg/models.nim
index febd1ea..6b3c1a4 100644
--- a/src/a3pkg/models.nim
+++ b/src/a3pkg/models.nim
@@ -11,6 +11,8 @@ type
createdAt*: DateTime
updatedAt*: DateTime
accessLevel*: int
+ totalQuantity*: int
+ totalPrice* :int
Products* = object
## Product is the product model
@@ -48,4 +50,4 @@ type
createdAt*: DateTime
updatedAt*: DateTime
orderStatus*: string
- orderDate*: DateTime
\ No newline at end of file
+ orderDate*: DateTime