Skip to content

Commit

Permalink
Modified serializer to allow only 100 beds at once
Browse files Browse the repository at this point in the history
  • Loading branch information
siddnikh committed Jul 11, 2023
1 parent 1c1d5cb commit 461b946
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions care/facility/api/serializers/bed.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ def validate(self, attrs):
raise ValidationError(
{"location": "Field is Required", "facility": "Field is Required"}
)

if attrs["number_of_beds"] > 100:
raise ValidationError(
{"number_of_beds": "Cannot create more than 100 beds at once."}
)
return super().validate(attrs)


Expand Down
2 changes: 1 addition & 1 deletion care/facility/api/viewsets/bed.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def create(self, request, *args, **kwargs):
validated_data = serializer.validated_data
number_of_beds = validated_data.pop("number_of_beds", 1)
# Bulk creating n number of beds
if number_of_beds > 1:
if number_of_beds > 1 and number_of_beds <= 100:
objs = []
for i in range(1, number_of_beds + 1):
temp_data = dict(validated_data.copy())
Expand Down

0 comments on commit 461b946

Please sign in to comment.