Skip to content

Commit dd50f80

Browse files
adds check for negative discount amount and percent
1 parent 9d204a2 commit dd50f80

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

app/api/schema/discount_codes.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ def validate_value(self, data, original_data):
112112
{'pointer': '/data/attributes/value'},
113113
"discount percent cannot be more than 100%"
114114
)
115+
if data['value'] < 0:
116+
raise UnprocessableEntity(
117+
{'pointer': '/data/attributes/value'},
118+
"discount percent cannot be less than 0%"
119+
)
115120

116121
if data['type'] == "amount":
117122
event_object = Event.query.filter_by(id=data['event']).one()
@@ -121,6 +126,11 @@ def validate_value(self, data, original_data):
121126
{'pointer': '/data/attributes/value'},
122127
"discount amount cannot be more than ticket amount"
123128
)
129+
if data['value'] < 0:
130+
raise UnprocessableEntity(
131+
{'pointer': '/data/attributes/value'},
132+
"discount amount cannot be less than zero"
133+
)
124134

125135
@validates_schema(pass_original=True)
126136
def validate_date(self, data, original_data):
@@ -205,6 +215,11 @@ def validate_value(self, data, original_data):
205215
{'pointer': '/data/attributes/value'},
206216
"discount percent cannot be more than 100%"
207217
)
218+
if data['value'] < 0:
219+
raise UnprocessableEntity(
220+
{'pointer': '/data/attributes/value'},
221+
"discount percent cannot be less than 0%"
222+
)
208223

209224
if data['type'] == "amount":
210225
for ticket in data['tickets']:
@@ -214,6 +229,11 @@ def validate_value(self, data, original_data):
214229
{'pointer': '/data/attributes/value'},
215230
"discount amount cannot be more than ticket amount"
216231
)
232+
if data['value'] < 0:
233+
raise UnprocessableEntity(
234+
{'pointer': '/data/attributes/value'},
235+
"discount amount cannot be less than zero"
236+
)
217237

218238
@validates_schema(pass_original=True)
219239
def validate_date(self, data, original_data):

0 commit comments

Comments
 (0)