fix: cycle date check endpoint (#1074)

This commit is contained in:
pablohashescobar 2023-05-19 13:00:38 +05:30 committed by GitHub
parent bb79c9de96
commit 06618006c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,7 +3,17 @@ import json
# Django imports # Django imports
from django.db import IntegrityError from django.db import IntegrityError
from django.db.models import OuterRef, Func, F, Q, Exists, OuterRef, Count, Prefetch, Sum from django.db.models import (
OuterRef,
Func,
F,
Q,
Exists,
OuterRef,
Count,
Prefetch,
Sum,
)
from django.core import serializers from django.core import serializers
from django.utils import timezone from django.utils import timezone
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
@ -433,7 +443,7 @@ class CycleDateCheckEndpoint(BaseAPIView):
try: try:
start_date = request.data.get("start_date", False) start_date = request.data.get("start_date", False)
end_date = request.data.get("end_date", False) end_date = request.data.get("end_date", False)
cycle_id = request.data.get("cycle_id")
if not start_date or not end_date: if not start_date or not end_date:
return Response( return Response(
{"error": "Start date and end date both are required"}, {"error": "Start date and end date both are required"},
@ -441,12 +451,14 @@ class CycleDateCheckEndpoint(BaseAPIView):
) )
cycles = Cycle.objects.filter( cycles = Cycle.objects.filter(
Q(workspace__slug=slug)
& Q(project_id=project_id)
& (
Q(start_date__lte=start_date, end_date__gte=start_date) Q(start_date__lte=start_date, end_date__gte=start_date)
| Q(start_date__lte=end_date, end_date__gte=end_date) | Q(start_date__lte=end_date, end_date__gte=end_date)
| Q(start_date__gte=start_date, end_date__lte=end_date), | Q(start_date__gte=start_date, end_date__lte=end_date)
workspace__slug=slug,
project_id=project_id,
) )
).exclude(pk=cycle_id)
if cycles.exists(): if cycles.exists():
return Response( return Response(