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>
<th> User </th>
<th> Last name </th>
<th> Email </th>
<th> Orders </th>
<th> Amount </th>
<th> Email </th>
</tr>
</thead>
<tbody>

View File

@ -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

View File

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