|
20 | 20 | from app.api.helpers.exceptions import ConflictException, MethodNotAllowed, UnprocessableEntity |
21 | 21 | from app.api.helpers.db import get_count |
22 | 22 |
|
| 23 | + |
| 24 | +def validate_ticket_price(data): |
| 25 | + if not data.get('price') or not data.get('type'): |
| 26 | + raise UnprocessableEntity({}, "Type/price of ticket is missing") |
| 27 | + if data.get('type') != 'free' and int(data.get('price')) <= 0: |
| 28 | + raise UnprocessableEntity( |
| 29 | + {'price': data.get('price')}, "Price of a paid/donation ticket must be greater than zero") |
| 30 | + |
| 31 | + |
23 | 32 | class TicketListPost(ResourceList): |
24 | 33 | """ |
25 | 34 | Create and List Tickets |
@@ -59,6 +68,7 @@ def before_create_object(self, data, view_kwargs): |
59 | 68 | if not event.is_payment_enabled(): |
60 | 69 | raise UnprocessableEntity( |
61 | 70 | {'event_id': data['event']}, "Event having paid ticket must have a payment method") |
| 71 | + validate_ticket_price(data) |
62 | 72 |
|
63 | 73 | schema = TicketSchema |
64 | 74 | methods = ['POST', ] |
@@ -181,6 +191,8 @@ def before_update_object(self, ticket, data, view_kwargs): |
181 | 191 | if not event.is_payment_enabled(): |
182 | 192 | raise UnprocessableEntity( |
183 | 193 | {'event_id': ticket.event.id}, "Event having paid ticket must have a payment method") |
| 194 | + if data: |
| 195 | + validate_ticket_price(data) |
184 | 196 |
|
185 | 197 | decorators = (api.has_permission('is_coorganizer', fetch='event_id', |
186 | 198 | fetch_as="event_id", model=Ticket, methods="PATCH,DELETE"),) |
|
0 commit comments