This commit is contained in:
Aritra Banik 2024-03-26 02:53:41 +05:30
parent 53dfa0f257
commit fd4d6df422
6 changed files with 40 additions and 12 deletions

Binary file not shown.

BIN
src/a3

Binary file not shown.

View File

@ -1,6 +1,9 @@
import db_connector/db_sqlite
import ../a3pkg/models
import
strutils,
../a3pkg/models,
./users
proc close*(db: DbConn) =
db.close()
@ -31,3 +34,24 @@ proc createOrder*(db: DbConn, order:Orders): int64 =
proc drop*(db: DbConn) =
db.exec(sql"DROP TABLE IF EXISTS orders")
proc getOrderAdmin*(db: DbConn): seq[User]=
var
row = db.getAllRows(sql"SELECT DISTINCT user_id FROM orders;")
users: seq[User]
for a, b in row:
var
u = db.getRow(sql"SELECT * FROM users WHERE id=?", b[0])
user: User
c = db.getUserOrdersAmount(parseInt(b[0]))
user.id = parseInt(u[0])
user.firstName = u[1]
user.lastName = u[2]
user.email = u[3]
user.totalQuantity = c[0]
user.totalPrice = c[1]
users.add(user)
return users

View File

@ -58,20 +58,20 @@ proc getUser*(db: DbConn, email, password: string): User =
return user
proc getUserOrdersAmount*(db: DbConn, userId: int): (int, int)=
proc getUserOrdersAmount*(db: DbConn, userId: int): (int, float)=
echo userId
var
row = db.getAllRows(sql"SELECT (product_id, quantity) FROM orders WHERE user_id=?", userId)
row = db.getAllRows(sql"SELECT * FROM orders WHERE user_id=?", userId)
totalQuantity = 0
totalPrice = 0
totalPrice = 0.0
echo row
for b, c in row:
var
quantity = c[1]
row1 = db.getValue(sql"SELECT price FROM products WHERE id=?", c[0])
quantity = c[8]
row1 = db.getValue(sql"SELECT price FROM products WHERE id=?", c[7])
totalQuantity = totalQuantity + parseInt(quantity)
totalPrice = totalPrice + parseInt(quantity) * parseInt(row1)
totalPrice = totalPrice + parseFloat(quantity) * parseFloat(row1)
return (totalQuantity, totalPrice)
proc getUserCartTable*(db: DbConn): seq[User]=

View File

@ -12,7 +12,7 @@ type
updatedAt*: DateTime
accessLevel*: int
totalQuantity*: int
totalPrice* :int
totalPrice* : float
Products* = object
## Product is the product model

View File

@ -2,13 +2,17 @@ import
mike,
nimja,
./a3pkg/mics,
./a3c/users
./a3c/[users, orders]
proc admin*(ctx: Context): string=
var
db = newDatabase()
users = db.getUserCartTable()
users = db.getOrderAdmin()
# users = db.getUserCartTable()
echo users
# echov v
# var users = db.getUserCartTable()
# echo users
compileTemplateFile(getScriptDir() / "a3a" / "admin" / "index.html")