From 7d9bc165889de4b269a3eed837e13517ad385297 Mon Sep 17 00:00:00 2001 From: Sean Morley Date: Mon, 7 Oct 2024 19:51:45 -0400 Subject: [PATCH] fixed --- backend/server/adventures/serializers.py | 28 +++++++++--------------- frontend/src/lib/index.ts | 11 ++++++---- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/backend/server/adventures/serializers.py b/backend/server/adventures/serializers.py index 992d853e..4bf7e8c0 100644 --- a/backend/server/adventures/serializers.py +++ b/backend/server/adventures/serializers.py @@ -17,14 +17,19 @@ def to_representation(self, instance): public_url = public_url.replace("'", "") representation['image'] = f"{public_url}/media/{instance.image.name}" return representation - - + +class VisitSerializer(serializers.ModelSerializer): + class Meta: + model = Visit + fields = ['id', 'start_date', 'end_date', 'notes'] + read_only_fields = ['id'] class AdventureSerializer(serializers.ModelSerializer): images = AdventureImageSerializer(many=True, read_only=True) + visits = VisitSerializer(many=True, read_only=False) class Meta: model = Adventure - fields = ['id', 'user_id', 'name', 'description', 'rating', 'activity_types', 'location', 'is_public', 'collection', 'created_at', 'updated_at', 'images', 'link', 'type', 'longitude', 'latitude'] + fields = ['id', 'user_id', 'name', 'description', 'rating', 'activity_types', 'location', 'is_public', 'collection', 'created_at', 'updated_at', 'images', 'link', 'type', 'longitude', 'latitude', 'visits'] read_only_fields = ['id', 'created_at', 'updated_at', 'user_id'] def to_representation(self, instance): @@ -70,7 +75,7 @@ def update(self, instance, validated_data): instance.visits.filter(id__in=visits_to_delete).delete() return instance - + class TransportationSerializer(serializers.ModelSerializer): class Meta: @@ -99,17 +104,7 @@ class Meta: 'id', 'user_id', 'name', 'is_checked', 'checklist', 'created_at', 'updated_at' ] read_only_fields = ['id', 'created_at', 'updated_at', 'user_id', 'checklist'] - - # def validate(self, data): - # # Check if the checklist is public and the checklist item is not - # checklist = data.get('checklist') - # is_checked = data.get('is_checked', False) - # if checklist and checklist.is_public and not is_checked: - # raise serializers.ValidationError( - # 'Checklist items associated with a public checklist must be checked.' - # ) - - + class ChecklistSerializer(serializers.ModelSerializer): items = ChecklistItemSerializer(many=True, source='checklistitem_set') class Meta: @@ -173,9 +168,6 @@ def validate(self, data): return data - - - class CollectionSerializer(serializers.ModelSerializer): adventures = AdventureSerializer(many=True, read_only=True, source='adventure_set') transportations = TransportationSerializer(many=True, read_only=True, source='transportation_set') diff --git a/frontend/src/lib/index.ts b/frontend/src/lib/index.ts index 548280bd..ff6b9bb2 100644 --- a/frontend/src/lib/index.ts +++ b/frontend/src/lib/index.ts @@ -266,8 +266,11 @@ export function isAdventureVisited(adventure: Adventure) { const currentTime = Date.now(); // Check if any visit's start_date is before the current time. - return adventure.visits.some((visit) => { - const visitStartTime = new Date(visit.start_date).getTime(); - return visit.start_date && visitStartTime <= currentTime; - }); + return ( + adventure.visits && + adventure.visits.some((visit) => { + const visitStartTime = new Date(visit.start_date).getTime(); + return visit.start_date && visitStartTime <= currentTime; + }) + ); }