chore: change one estimate point to another (#4845)

This commit is contained in:
Bavisetti Narayan 2024-06-17 18:26:49 +05:30 committed by GitHub
parent 6a997bb9da
commit 909fe128f1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -62,12 +62,15 @@ class BulkEstimatePointEndpoint(BaseViewSet):
path="/api/workspaces/:slug/estimates/", url_params=True, user=False path="/api/workspaces/:slug/estimates/", url_params=True, user=False
) )
def create(self, request, slug, project_id): def create(self, request, slug, project_id):
estimate = request.data.get('estimate') estimate = request.data.get("estimate")
estimate_name = estimate.get("name", generate_random_name()) estimate_name = estimate.get("name", generate_random_name())
estimate_type = estimate.get("type", 'categories') estimate_type = estimate.get("type", "categories")
last_used = estimate.get("last_used", False) last_used = estimate.get("last_used", False)
estimate = Estimate.objects.create( estimate = Estimate.objects.create(
name=estimate_name, project_id=project_id, last_used=last_used, type=estimate_type name=estimate_name,
project_id=project_id,
last_used=last_used,
type=estimate_type,
) )
estimate_points = request.data.get("estimate_points", []) estimate_points = request.data.get("estimate_points", [])
@ -125,8 +128,12 @@ class BulkEstimatePointEndpoint(BaseViewSet):
estimate = Estimate.objects.get(pk=estimate_id) estimate = Estimate.objects.get(pk=estimate_id)
if request.data.get("estimate"): if request.data.get("estimate"):
estimate.name = request.data.get("estimate").get("name", estimate.name) estimate.name = request.data.get("estimate").get(
estimate.type = request.data.get("estimate").get("type", estimate.type) "name", estimate.name
)
estimate.type = request.data.get("estimate").get(
"type", estimate.type
)
estimate.save() estimate.save()
estimate_points_data = request.data.get("estimate_points", []) estimate_points_data = request.data.get("estimate_points", [])
@ -204,7 +211,9 @@ class EstimatePointEndpoint(BaseViewSet):
serializer = EstimatePointSerializer(estimate_point).data serializer = EstimatePointSerializer(estimate_point).data
return Response(serializer, status=status.HTTP_200_OK) return Response(serializer, status=status.HTTP_200_OK)
def partial_update(self, request, slug, project_id, estimate_id, estimate_point_id): def partial_update(
self, request, slug, project_id, estimate_id, estimate_point_id
):
# TODO: add a key validation if the same key already exists # TODO: add a key validation if the same key already exists
estimate_point = EstimatePoint.objects.get( estimate_point = EstimatePoint.objects.get(
pk=estimate_point_id, pk=estimate_point_id,
@ -225,7 +234,7 @@ class EstimatePointEndpoint(BaseViewSet):
def destroy( def destroy(
self, request, slug, project_id, estimate_id, estimate_point_id self, request, slug, project_id, estimate_id, estimate_point_id
): ):
new_estimate_id = request.GET.get("new_estimate_id", None) new_estimate_id = request.data.get("new_estimate_id", None)
estimate_points = EstimatePoint.objects.filter( estimate_points = EstimatePoint.objects.filter(
estimate_id=estimate_id, estimate_id=estimate_id,
project_id=project_id, project_id=project_id,
@ -236,8 +245,8 @@ class EstimatePointEndpoint(BaseViewSet):
_ = Issue.objects.filter( _ = Issue.objects.filter(
project_id=project_id, project_id=project_id,
workspace__slug=slug, workspace__slug=slug,
estimate_id=estimate_point_id, estimate_point_id=estimate_point_id,
).update(estimate_id=new_estimate_id) ).update(estimate_point_id=new_estimate_id)
# delete the estimate point # delete the estimate point
old_estimate_point = EstimatePoint.objects.filter( old_estimate_point = EstimatePoint.objects.filter(