diff --git a/server/models.py b/server/models.py index c4e2fa1..dd4aaa2 100644 --- a/server/models.py +++ b/server/models.py @@ -21,6 +21,12 @@ class Order(db.Model): region_code = db.Column(db.Integer) channel = db.Column(db.Integer, default=1) invoices = db.relationship('Invoice', backref='order', lazy=True) + tx_confirmations = db.relationship('TxConfirmation', + backref='order', + lazy=True) + rx_confirmations = db.relationship('RxConfirmation', + backref='order', + lazy=True) class Invoice(db.Model): diff --git a/server/orders.py b/server/orders.py index 0930b26..ce5c521 100644 --- a/server/orders.py +++ b/server/orders.py @@ -16,7 +16,7 @@ from error import get_http_error_resp from invoice_helpers import new_invoice, pay_invoice from models import Order, RxConfirmation, TxConfirmation from regions import region_number_list_to_code -from schemas import order_schema, orders_schema,\ +from schemas import admin_order_schema, order_schema, orders_schema,\ order_upload_req_schema, order_bump_schema,\ rx_confirmation_schema, tx_confirmation_schema import bidding @@ -50,8 +50,8 @@ class OrderResource(Resource): constants.CHANNEL_INFO[order.channel].user_permissions: return get_http_error_resp('ORDER_CHANNEL_UNAUTHORIZED_OP', order.channel) - - return order_schema.dump(order) + schema = admin_order_schema if admin_mode else order_schema + return schema.dump(order) def delete(self, uuid): admin_mode = request.path.startswith("/admin/") diff --git a/server/schemas.py b/server/schemas.py index c36f682..81042c8 100644 --- a/server/schemas.py +++ b/server/schemas.py @@ -3,7 +3,8 @@ from datetime import datetime, timedelta from marshmallow import fields, Schema, validate, ValidationError -from regions import all_region_numbers, region_code_to_number_list +from regions import all_region_numbers, region_code_to_number_list, \ + region_id_to_number import constants @@ -25,6 +26,16 @@ class OrderSchema(Schema): lambda obj: region_code_to_number_list(obj.region_code)) +class AdminOrderSchema(OrderSchema): + channel = fields.Integer() + tx_confirmations = fields.Function( + lambda obj: + [region_id_to_number(x.region_id) for x in obj.tx_confirmations]) + rx_confirmations = fields.Function( + lambda obj: + [region_id_to_number(x.region_id) for x in obj.rx_confirmations]) + + def must_be_region_number(input): if input not in all_region_numbers: raise ValidationError( @@ -81,6 +92,7 @@ class RxConfirmationSchema(Schema): order_schema = OrderSchema() +admin_order_schema = AdminOrderSchema() order_upload_req_schema = OrderUploadReqSchema() order_bump_schema = OrderBumpSchema() orders_schema = OrdersSchema()