diff --git a/src/a3c/cart.nim b/src/a3c/cart.nim index b720594..ba4df4d 100644 --- a/src/a3c/cart.nim +++ b/src/a3c/cart.nim @@ -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) \ No newline at end of file + db.exec(sql"DELETE FROM cart WHERE user_id=?", userId) diff --git a/src/a3c/orders.nim b/src/a3c/orders.nim index d3c7810..1ee07b4 100644 --- a/src/a3c/orders.nim +++ b/src/a3c/orders.nim @@ -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