Skip to content

Commit

Permalink
Bidding system is now connected to DB. Added temporary page for deliv…
Browse files Browse the repository at this point in the history
…ery status.
  • Loading branch information
raynelfss committed May 11, 2022
1 parent b79874c commit e736a5d
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 12 deletions.
2 changes: 1 addition & 1 deletion api/bidding.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def index(): # route to handle requests
if not helpers.isDeliveryBoy(): abort(403)
try:
data = request.json
bidding.addBid( data['bidID'], session['employeeID'], data['amount'], data['orderID'] )
bidding.addBid( session['employeeID'], data['amount'], data['orderID'] )
return { 'response': 'successfully posted bid' }

except Exception as e:
Expand Down
1 change: 1 addition & 0 deletions build/bid-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

{% if session.get('employeeType') == 'deliveryPerson' %}
{% block body %}
<h1>Available orders:</h1>
<div class="orders">
<!-- display delivery orders without deliverers -->
<!-- <div class="order">
Expand Down
1 change: 1 addition & 0 deletions build/dashboard-deliverystat.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% extends 'dashboard-layout.html' %}
40 changes: 33 additions & 7 deletions build/scripts/bids.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var isModalOpen = false;

async function getOrders() { // Retreive orders pending orders from database.
const response = await fetch('/api/order');
const data = await response.json();
Expand All @@ -15,7 +17,7 @@ function getBid() {
async function postBid(orderID) {
const amount = getBid();
const data = JSON.stringify({ amount, orderID });
const response = await fetch('/api/orders', {
const response = await fetch('/api/bids/', {
method: 'POST',
headers: {
'Accept': 'application/json',
Expand Down Expand Up @@ -44,18 +46,36 @@ function createOrder(order) {
}

async function loadOrders() {
const orders = await getOrders();
const orders = await getOrders() || [];
const ordersDiv = document.getElementsByClassName('orders')[0];
orders.forEach(order => {
const orderDiv = createOrder(order);
ordersDiv.appendChild(orderDiv);
})
if (orders.length > 0) {
orders.forEach(order => {
const orderDiv = createOrder(order);
ordersDiv.appendChild(orderDiv);
})
}
else {
ordersDiv.appendChild(createElement("h1", {"text" : "There are no active orders at the moment."}))
}
}

function clearOrders() {
let children = document.getElementsByClassName('order') || [];
Array.from(children).forEach(element => {
element.remove();
});
}

function reload() {
clearOrders();
loadOrders();
}

// bid modal


function openBidModal(orderID) {
isModalOpen = true;
const modalContainer = document.getElementsByClassName('modalContainer')[0];
document.getElementsByClassName('modalCancel')[0].setAttribute('onclick', 'closeBidModal()');
document.getElementsByClassName('place')[0].setAttribute('onclick', `postBid(${orderID})`);
Expand All @@ -66,6 +86,12 @@ function openBidModal(orderID) {
function closeBidModal() {
const modalContainer = document.getElementsByClassName('modalContainer')[0];
modalContainer.style.display = 'none';
isModalOpen = false;
}

loadOrders()
reload();
setInterval(() => {
if(!isModalOpen) {
reload();
}
}, 10000);
8 changes: 4 additions & 4 deletions database/bidding.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ def deleteTable(): # testing
with DatabaseConnection('./database/database.db') as cursor:
cursor.execute("DROP TABLE IF EXISTS BiddingSystemTable")

def addBid(bidID, employeeID, amount, orderID): # creates bid
def addBid(employeeID, amount, orderID): # creates bid
with DatabaseConnection('./database/database.db') as cursor:
rows = cursor.execute("""INSERT INTO BiddingSystemTable (BidID, EmployeeID,
Amount, OrderID) VALUES (?,?,?,?) RETURNING *""",
(bidID, employeeID, amount, orderID))
rows = cursor.execute("""INSERT INTO BiddingSystemTable (EmployeeID,
Amount, OrderID) VALUES (?,?,?) RETURNING *""",
(employeeID, amount, orderID))
bid = [listToDict(row) for row in rows][0]
return bid

Expand Down
Binary file modified database/database.db
Binary file not shown.

0 comments on commit e736a5d

Please sign in to comment.