From 6269720a9ee496b27c4857602f6b6ef95f48a2e1 Mon Sep 17 00:00:00 2001 From: Clara Date: Sun, 27 Oct 2024 14:58:54 +0000 Subject: [PATCH] feat: API work to expose miscCosts for frontend query (#851) * Expose some miscCosts info * Fix failing tests --- schema.graphql | 11 +++++++++++ uobtheatre/bookings/models.py | 6 ++++-- uobtheatre/bookings/schema.py | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/schema.graphql b/schema.graphql index bca61fd9e..7f82f9494 100644 --- a/schema.graphql +++ b/schema.graphql @@ -337,6 +337,16 @@ type MiscCostNode implements Node { value: Float } +type MiscCostNodeConnection { + pageInfo: PageInfo! + edges: [MiscCostNodeEdge]! +} + +type MiscCostNodeEdge { + node: MiscCostNode + cursor: String! +} + type Mutation { recordFinancialTransfer(method: TransferMethodEnum!, reason: String, societyId: IdInputField!, value: Int!): RecordFinancialTransfer concessionType(input: ConcessionTypeMutationInput!): ConcessionTypeMutationPayload @@ -666,6 +676,7 @@ input ProductionWarning { type Query { images: [ImageNode] paymentDevices(paymentProvider: PaymentProvider, paired: Boolean): [SquarePaymentDevice] + miscCosts(offset: Int, before: String, after: String, first: Int, last: Int, id: ID, name: String): MiscCostNodeConnection bookings(offset: Int, before: String, after: String, first: Int, last: Int, createdAt: DateTime, updatedAt: DateTime, status: String, user: ID, creator: ID, reference: String, performance: ID, adminDiscountPercentage: Float, accessibilityInfo: String, expiresAt: DateTime, id: ID, statusIn: [String], search: String, productionSearch: String, productionSlug: String, performanceId: String, checkedIn: Boolean, active: Boolean, expired: Boolean, orderBy: String): BookingNodeConnection me: ExtendedUserNode societies(offset: Int, before: String, after: String, first: Int, last: Int, id: ID, name: String, slug: String, userHasPermission: String): SocietyNodeConnection diff --git a/uobtheatre/bookings/models.py b/uobtheatre/bookings/models.py index 6b6a77bd7..a7d06acfb 100644 --- a/uobtheatre/bookings/models.py +++ b/uobtheatre/bookings/models.py @@ -58,8 +58,10 @@ class MiscCost(models.Model): Additional costs are added to a booking's final total. For example: Booking fee/Theatre improvement levy. - A misc costs is defined by either a value or a percentage. If both are - supplied the percentage will take precedence. + A misc costs is defined by either a value or a percentage, but not both. + + Percentages are in decimal form (e.g. 0.1 for 10%). + Value is in pence. Note: Currently all misc costs are applied to all bookings. diff --git a/uobtheatre/bookings/schema.py b/uobtheatre/bookings/schema.py index 1f3f45f10..b4e6aa54c 100644 --- a/uobtheatre/bookings/schema.py +++ b/uobtheatre/bookings/schema.py @@ -16,10 +16,27 @@ from uobtheatre.utils.filters import FilterSet +class MiscCostFilter(FilterSet): + class Meta: + model = MiscCost + fields = ( + "id", + "name", + ) + + class MiscCostNode(DjangoObjectType): class Meta: model = MiscCost interfaces = (relay.Node,) + filterset_class = MiscCostFilter + fields = ( + "id", + "name", + "description", + "percentage", + "value", + ) class TicketNode(DjangoObjectType): @@ -350,4 +367,5 @@ class Query(graphene.ObjectType): These queries are appended to the main schema Query. """ + miscCosts = DjangoFilterConnectionField(MiscCostNode) bookings = DjangoFilterConnectionField(BookingNode)