From 461b946f6bff2e93f6eb73098a66b98e96e4d95d Mon Sep 17 00:00:00 2001 From: siddnikh Date: Tue, 11 Jul 2023 20:18:54 +0530 Subject: [PATCH] Modified serializer to allow only 100 beds at once --- care/facility/api/serializers/bed.py | 5 +++++ care/facility/api/viewsets/bed.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/care/facility/api/serializers/bed.py b/care/facility/api/serializers/bed.py index 65ac3ac339..3ed8cbdfb3 100644 --- a/care/facility/api/serializers/bed.py +++ b/care/facility/api/serializers/bed.py @@ -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) diff --git a/care/facility/api/viewsets/bed.py b/care/facility/api/viewsets/bed.py index a87845678f..ad652033f9 100644 --- a/care/facility/api/viewsets/bed.py +++ b/care/facility/api/viewsets/bed.py @@ -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())