added checks emergency fixed bugs

This commit is contained in:
2024-09-27 14:13:44 -04:00
parent 0e827053de
commit fec638a5c8
13 changed files with 262 additions and 68 deletions

View File

@@ -5,7 +5,7 @@ from app.stats import stats
from app import db
from app.classes.delivery import Delivery_Delivery
from app.classes.stats_company import Stats_Company, Stats_Company_schema
from app.classes.stats_customer import Stats_Customer, Stats_Customer_schema
@stats.route("/calls/add", methods=["PUT"])
def total_calls_post():
@@ -101,3 +101,52 @@ def total_deliveries_today_finished():
'data': total_stops,
}), 200
@stats.route("/user/<int:user_id>", methods=["GET"])
def get_user_stats(user_id):
"""
gets stats of user
"""
get_user = db.session \
.query(Stats_Customer) \
.filter(Stats_Customer.customer_id == user_id) \
.first()
if get_user is None:
new_stats = Stats_Customer(
customer_id = user_id,
total_calls = 1,
service_calls_total = 0,
service_calls_total_spent = 0,
service_calls_total_profit = 0,
oil_deliveries = 0,
oil_total_gallons = 0,
oil_total_spent = 0,
oil_total_profit = 0,
)
db.session.add(new_stats)
db.session.commit()
get_user = db.session \
.query(Stats_Customer) \
.filter(Stats_Customer.customer_id == user_id) \
.first()
user_schema = Stats_Customer_schema(many=False)
return jsonify(user_schema.dump(get_user))
@stats.route("/user/lastdelivery/<int:user_id>", methods=["GET"])
def get_user_last_delivery(user_id):
"""
gets users last delivery. used on profile page
"""
get_delivery= db.session \
.query(Delivery_Delivery) \
.filter(Delivery_Delivery.customer_id == user_id) \
.order_by(Delivery_Delivery.id.desc())\
.first()
if get_delivery:
date_delivered = get_delivery.when_delivered
else:
date_delivered = "no deliveries on record"
return jsonify({"ok": True,
'date': date_delivered,
}), 200