This commit is contained in:
Aritra Banik 2024-03-24 14:44:12 +05:30
parent 30fef95b94
commit e8760ab1a7
3 changed files with 24 additions and 11 deletions

View File

@ -514,9 +514,9 @@
<tr> <tr>
<th> User </th> <th> User </th>
<th> Last name </th> <th> Last name </th>
<th> Email </th>
<th> Orders </th> <th> Orders </th>
<th> Amount </th> <th> Amount </th>
<th> Email </th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>

View File

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

View File

@ -11,6 +11,8 @@ type
createdAt*: DateTime createdAt*: DateTime
updatedAt*: DateTime updatedAt*: DateTime
accessLevel*: int accessLevel*: int
totalQuantity*: int
totalPrice* :int
Products* = object Products* = object
## Product is the product model ## Product is the product model
@ -48,4 +50,4 @@ type
createdAt*: DateTime createdAt*: DateTime
updatedAt*: DateTime updatedAt*: DateTime
orderStatus*: string orderStatus*: string
orderDate*: DateTime orderDate*: DateTime