Skip to content

Commit

Permalink
Connected orders-employee table to bids
Browse files Browse the repository at this point in the history
  • Loading branch information
raynelfss committed May 11, 2022
1 parent a689cf1 commit f0fc1fb
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 12 deletions.
17 changes: 9 additions & 8 deletions api/bidding.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,37 +37,38 @@ def index(): # route to handle requests
abort(500)

@bidsBlueprint.route('/<id>', methods = ['GET', 'DELETE'])
def bid(bidID):
def bid(id):
if request.method == 'GET':
# if not helpers.isDeliveryBoy(): abort(403)
try: return { 'response': bidding.getBidsByID(bidID) }
try: return { 'response': bidding.getBidsByID(id) }
except Exception as e:
print(e, '\n')
abort(500)

elif request.method == 'DELETE':
if not helpers.isDeliveryBoy() or not helpers.isManager(): abort(403) # not authorized
try:
bidding.deleteBid(bidID)
bidding.deleteBid(id)
return { 'response': 'deleted' }
except Exception as e:
print('error: ', e, '\n')
abort(500)

@bidsBlueprint.route('/orderID/<id>', methods = ['GET', 'DELETE'])
def bidsOnOrder(orderID):
def bidsOnOrder(id):
if request.method == 'GET':
if not helpers.isManager(): abort(403)

try: return { 'response': bidding.getBidsByOrderID(orderID) }
if not (helpers.isManager() or helpers.isChef()): abort(403)
try:
print('I\'m here')
return { 'response': bidding.getBidsByOrderID(id) }
except Exception as e:
print('error: ', e, '\n')
abort(500)

elif request.method == 'DELETE':
if not helpers.isManager(): abort(403) # not authorized
try:
bidding.deleteBidByOrderID(orderID)
bidding.deleteBidByOrderID(id)
return { 'response': 'deleted' }

except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion api/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def order(id):
@orderBlueprint.route('/inprogress', methods=['GET'])
def inProgress():
if request.method == 'GET':
if not isChef(): abort(403) # not authorized
if not (isChef() or isDeliveryBoy()): abort(403) # not authorized
try:
ordersInProgress = orders.getOrdersInProgress()
return { 'response': ordersInProgress }
Expand Down
5 changes: 5 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ def bid():
if helpers.isLoggedIn() and helpers.isDeliveryBoy():
return render_template("bid-page.html", nav = helpers.getSidebarNav(), currentUrl = '/dashboard/bid')

@app.route('/dashboard/deliverystatus')
def deliverystatus():
if helpers.isLoggedIn():
return render_template("dashboard-deliverystat.html", nav = helpers.getSidebarNav(), currentUrl = '/dashboard/deliverystatus')

@app.route('/login')
def login():
if helpers.isLoggedIn(): return redirect('/')
Expand Down
14 changes: 13 additions & 1 deletion build/dashboard-deliverystat.html
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
{% extends 'dashboard-layout.html' %}
{% extends 'dashboard-layout.html' %}

{% block head %}
<title>Dashboard: Status</title>
{% endblock %}

{% block body %}
<div class="title">
<h2>Welcome to Dashboard</h2>
<!-- will prob display different stuff here based on employee -->
</div>

{% endblock %}
1 change: 1 addition & 0 deletions build/orders-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ <h2 id="currentTime"></h2>
</tr>
</table>
<script src="/scripts/order-page.js"></script>
<script src="/scripts/bidpicking.js"></script>
</div>
{% endblock %}

13 changes: 13 additions & 0 deletions build/scripts/bidpicking.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

async function autoAssign(id) {
const allbids = await getBids(id);
console.log(id);
console.log(allbids);
}

async function getBids(id) {
const response = await fetch('/api/bids/orderID/' + String(id))
const data = await response.json();
// console.log(data);
return data['response'];
}
2 changes: 1 addition & 1 deletion build/scripts/bids.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var isModalOpen = false;

async function getOrders() { // Retreive orders pending orders from database.
const response = await fetch('/api/order');
const response = await fetch('/api/order/inprogress');
const data = await response.json();

if (response.headers.get("content-type") === 'application/json') {
Expand Down
2 changes: 1 addition & 1 deletion build/scripts/order-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function filltable(data) {
// when filing in column for employeeID, check if employeeID exists and if it's a delivery
if (order['employeeID'] == null && order['deliveryMethod'] == 'delivery') {
let button = createElement('td');
button.appendChild(createElement('button', { text: 'Assign' }));
button.appendChild(createElement('button', { text: 'Assign', onclick: `autoAssign(${order.orderID})` }));
column = button;
} // if delivery have a button to assign deliveryBoy
else {
Expand Down
Binary file modified database/database.db
Binary file not shown.
1 change: 1 addition & 0 deletions helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def getSidebarNav():
{'url': '/', 'name': 'Home'},
{'url': '/dashboard', 'name': 'Dashboard'},
{'url': '/dashboard/bid', 'name':'Biddings'},
{'url': '/dashboard/deliverystatus', 'name':'Delivery Status'},
{'url': '/logout', 'name':'Logout'},
]
elif isCustomer():
Expand Down

0 comments on commit f0fc1fb

Please sign in to comment.