def update(id: int):
    d = db.select(table="deliveries", conditions={"id": id}, multiple=False)
    if d is None:
        return jsonify(info="Delivery not found"), 404

    args = request.get_json(force=True)
    delivery = Delivery.parse(args, "update")
    if "errors" in delivery:
        return jsonify(errors=delivery["errors"]), 400
    delivery = delivery["delivery"]

    delivery["company_id"] = session["user"]["company_id"]

    # customer_id
    if "customer_id" in delivery:
        if not db.is_existing(table="customers", conditions={"id": delivery["customer_id"]}):
            return jsonify(info="Customer not found"), 404

        # sender_id
    if "sender_id" in delivery:
        if not db.is_existing(table="customers", conditions={"id": delivery["sender_id"]}):
            return jsonify(info="Sender not found"), 404

        # receiver_id
    if "receiver_id" in delivery:
        if not db.is_existing(table="customers", conditions={"id": delivery["receiver_id"]}):
            return jsonify(info="Receiver not found"), 404

    if "date_due" in delivery and d["driver_id"] is not None:
        db.delete(table="delivery_orders", conditions={"delivery_id": id})  # delete old date
        insert_at_last_order(id, delivery["date_due"], d["driver_id"])

    db.update(table="deliveries", params=delivery, conditions={"id": id})

    return jsonify(info="Delivery updated successfully"), 200
def delete(id:int):
    company_id = session["user"]["company_id"]
    if not db.is_existing(table="users", conditions={"id":id, "type":"driver","company_id": company_id}):
        return jsonify(info="Driver not found"), 404

    db.delete(table="users", conditions={"id":id})
    return jsonify(info="Driver deleted successfully"),200
def delete(id: int):
    company_id = session["user"]["company_id"]
    if not db.is_existing(table="vehicles", conditions={"id": id, "company_id": company_id}):
        return jsonify(info="Vehicle not found"), 404

    db.delete(table="vehicles", conditions={"id": id})
    return jsonify(info="Vehicle deleted successfully"), 200
예제 #4
0
def groups_remove(group_id):

    g = Group.query.get(group_id)
    if g.created_by == current_user.id:
        db.delete(g)
        db.session().commit()

    return redirect(url_for("polls_index"))
def delete(id:int):
    company_id = session["user"]["company_id"]
    existing_customer = db.is_existing(table="customers",conditions={"id": id, "company_id": company_id})
    if existing_customer is False:
        return jsonify(info="Customer not found"),404

    db.delete(table="customers", conditions={"id":id})
    return jsonify(info="Customer deleted successfully"),200
def delete(id: int):
    if not db.is_existing(table="deliveries", conditions={"id": id, "company_id": session["user"]["company_id"]}):
        return jsonify(info="Delivery not found"), 404

    db.delete(table="deliveries", conditions={"id": id})
    return jsonify(info="Delivery deleted successfully"), 200