This commit is contained in:
cereci5049 2024-04-15 13:03:09 +05:30
parent c80ae9395e
commit 02053b836e
2 changed files with 24 additions and 2 deletions

View File

@ -1,4 +1,7 @@
import db_connector/db_sqlite, strutils, strtabs
import
db_connector/db_sqlite,
strutils,
strtabs
import ../a3pkg/models
@ -60,4 +63,4 @@ proc updateCart*(db: DbConn, quantity: string, id: int) =
proc clearCart*(db: DbConn, userId: int) =
## clear the cart of the user
db.exec(sql"DELETE FROM cart WHERE user_id=?", userId)
db.exec(sql"DELETE FROM cart WHERE user_id=?", userId)

View File

@ -55,3 +55,22 @@ proc getOrderAdmin*(db: DbConn): seq[User]=
users.add(user)
return users
proc getOrders*(db: DbConn, userId: int): seq[Orders]=
var
rows = db.getAllRows(sql"SELECT * FROM orders WHERE user_id=?", userId)
orders: seq[Orders]
for id, row in rows:
var order: Orders
order.id = parseInt(row[0])
order.userId = parseInt(row[1])
order.country = row[2]
order.address = row[3]
order.state = row[4]
order.postalCode = row[5]
order.quantity = parseInt(row[6])
orders.add(order)
return orders