""" Provides general routes. """ from flask import jsonify from piket_server.flask import app from piket_server.models import Consumption @app.route("/ping") def ping() -> str: """ Return a status ping. """ return "Pong" @app.route("/status") def status(): """ Return a status dict with info about the database. """ unsettled_q = Consumption.query.filter_by(settlement=None).filter_by(reversed=False) unsettled = unsettled_q.count() first = None last = None if unsettled: last = ( unsettled_q.order_by(Consumption.created_at.desc()) .first() .created_at.isoformat() ) first = ( unsettled_q.order_by(Consumption.created_at.asc()) .first() .created_at.isoformat() ) return jsonify({"unsettled": {"amount": unsettled, "first": first, "last": last}})