diff --git a/backend/entities/models.py b/backend/entities/models.py index b18c0baa4..dfaacfd3d 100644 --- a/backend/entities/models.py +++ b/backend/entities/models.py @@ -53,7 +53,9 @@ def __str__(self) -> str: class Group(models.Model): id = models.UUIDField(primary_key=True, default=uuid4, editable=False) - org_id = models.ForeignKey(Organization, on_delete=models.CASCADE) + org_id = models.ForeignKey( + Organization, on_delete=models.CASCADE, related_name="groups" + ) created_by = models.ForeignKey("authentication.UserModel", on_delete=models.CASCADE) group_name = models.CharField(max_length=255) name = models.CharField(max_length=255) diff --git a/backend/entities/serializers.py b/backend/entities/serializers.py index 00b0f37c5..9306829f5 100644 --- a/backend/entities/serializers.py +++ b/backend/entities/serializers.py @@ -88,6 +88,7 @@ class OrganizationSerializer(serializers.ModelSerializer[Organization]): location = LocationSerializer(read_only=True) events = EventSerializer(many=True, read_only=True) resources = ResourceSerializer(many=True, read_only=True) + groups = GroupSerializer(many=True, read_only=True) class Meta: model = Organization diff --git a/frontend/components/feed/Feed.vue b/frontend/components/feed/Feed.vue index 58b8454a9..20344bae4 100644 --- a/frontend/components/feed/Feed.vue +++ b/frontend/components/feed/Feed.vue @@ -35,8 +35,7 @@ const feedItemNames = computed(() => { const feedItemUrls = computed(() => { if (organization && organization.groups) { return organization.groups.map( - (group: Group) => - `/organizations/${group.organization.id}/groups/${group.id}` + (group: Group) => `/organizations/${organization.id}/groups/${group.id}` ); } else { return [""]; diff --git a/frontend/composables/useLinkURL.ts b/frontend/composables/useLinkURL.ts index ab9b80217..fe6087ebd 100644 --- a/frontend/composables/useLinkURL.ts +++ b/frontend/composables/useLinkURL.ts @@ -17,8 +17,8 @@ export function useLinkURL(props: { let url: string = ""; if (props.organization) { url = `/organizations/${props.organization.id}`; - } else if (props.group) { - url = `/organizations/${props.group.organization.id}/groups/${props.group.id}`; + // } else if (props.group) { + // url = `/organizations/${props.group.organization.id}/groups/${props.group.id}`; } else if (props.event) { url = `/events/${props.event.id}`; } else if (props.resource) { diff --git a/frontend/stores/event.ts b/frontend/stores/event.ts index 0e99ca575..e1e86618e 100644 --- a/frontend/stores/event.ts +++ b/frontend/stores/event.ts @@ -2,8 +2,6 @@ import type { Event, EventCreateFormData, EventUpdateTextFormData, - PiniaResEvent, - PiniaResEvents, } from "~/types/events/event"; interface EventStore { @@ -101,24 +99,24 @@ export const useEventStore = defineStore("event", { async fetchById(id: string | undefined) { this.loading = true; - const resEvent = (await useAsyncData( - async () => await fetchWithoutToken(`/events/events/${id}`, {}) - ).data) as unknown as PiniaResEvent; - - const event = resEvent._value; - - this.event.id = event.id; - this.event.name = event.name; - this.event.tagline = event.tagline; - this.event.iconUrl = event.iconUrl; - - this.event.offlineLocation = event.offlineLocation; - - this.event.getInvolvedUrl = event.getInvolvedUrl; - this.event.socialLinks = event.socialLinks; + const { data, status } = await useAsyncData( + async () => + (await fetchWithoutToken(`/events/events/${id}/`, {})) as Event + ); - this.event.eventTextId = event.texts.eventId; - this.event.texts = event.texts; + if (status.value === "success") { + const event = data.value!; + + this.event.id = event.id; + this.event.name = event.name; + this.event.tagline = event.tagline; + this.event.iconUrl = event.iconUrl; + this.event.offlineLocation = event.offlineLocation; + this.event.getInvolvedUrl = event.getInvolvedUrl; + this.event.socialLinks = event.socialLinks; + this.event.eventTextId = event.texts.eventId; + this.event.texts = event.texts; + } this.loading = false; }, @@ -128,14 +126,12 @@ export const useEventStore = defineStore("event", { async fetchAll() { this.loading = true; - const responseEvents = await useAsyncData( - async () => await fetchWithoutToken(`/events/events/`, {}) + const { data, status } = await useAsyncData( + async () => (await fetchWithoutToken(`/events/events/`, {})) as Event[] ); - const allEvents = responseEvents.data as unknown as PiniaResEvents; - - if (allEvents._value) { - const events = allEvents._value.map((event: Event) => { + if (status.value === "success") { + const events = data.value!.map((event: Event) => { return { id: event.id, name: event.name, diff --git a/frontend/stores/group.ts b/frontend/stores/group.ts index 86252f7f3..09e4497bf 100644 --- a/frontend/stores/group.ts +++ b/frontend/stores/group.ts @@ -2,8 +2,6 @@ import type { Group, GroupCreateFormData, GroupUpdateTextFormData, - PiniaResGroup, - PiniaResGroups, } from "~/types/entities/group"; interface GroupStore { @@ -95,26 +93,26 @@ export const useGroupStore = defineStore("group", { async fetchById(id: string | undefined) { this.loading = true; - const groupRes = ( - await useAsyncData( - async () => await fetchWithoutToken(`/entities/groups/${id}`, {}) - ) - ).data as unknown as PiniaResGroup; - - const group = groupRes._value; + const { data, status } = await useAsyncData( + async () => + (await fetchWithoutToken(`/entities/groups/${id}/`, {})) as Group + ); - this.group.id = group.id; - this.group.name = group.name; - this.group.tagline = group.tagline; - this.group.organization = group.organization; + if (status.value === "success") { + const group = data.value!; + this.group.id = group.id; + this.group.name = group.name; + this.group.tagline = group.tagline; + this.group.organization = group.organization; - this.group.location = group.location; + this.group.location = group.location; - this.group.getInvolvedUrl = group.getInvolvedUrl; - this.group.socialLinks = group.socialLinks; + this.group.getInvolvedUrl = group.getInvolvedUrl; + this.group.socialLinks = group.socialLinks; - this.group.groupTextId = group.texts.groupId; - this.group.texts = group.texts; + this.group.groupTextId = group.texts.groupId; + this.group.texts = group.texts; + } this.loading = false; }, @@ -124,14 +122,13 @@ export const useGroupStore = defineStore("group", { async fetchAll() { this.loading = true; - const responseGroups = await useAsyncData( - async () => await fetchWithoutToken(`/entities/groups/`, {}) + const { data, status } = await useAsyncData( + async () => + (await fetchWithoutToken(`/entities/groups/`, {})) as Group[] ); - const allGroups = responseGroups.data as unknown as PiniaResGroups; - - if (allGroups._value) { - const groups = allGroups._value.map((group: Group) => { + if (status.value === "success") { + const groups = data.value!.map((group: Group) => { return { id: group.id, groupName: group.groupName, diff --git a/frontend/stores/organization.ts b/frontend/stores/organization.ts index 93edf72fa..b00b0e900 100644 --- a/frontend/stores/organization.ts +++ b/frontend/stores/organization.ts @@ -2,8 +2,6 @@ import type { Organization, OrganizationCreateFormData, OrganizationUpdateTextFormData, - PiniaResOrganization, - PiniaResOrganizations, } from "~/types/entities/organization"; interface OrganizationStore { @@ -93,28 +91,33 @@ export const useOrganizationStore = defineStore("organization", { async fetchById(id: string | undefined) { this.loading = true; - const responseOrg = (await useAsyncData( - async () => await fetchWithoutToken(`/entities/organizations/${id}`, {}) - ).data) as unknown as PiniaResOrganization; - - const organization = responseOrg._value; + const { data, status } = await useAsyncData( + async () => + (await fetchWithoutToken( + `/entities/organizations/${id}/`, + {} + )) as Organization + ); - this.organization.id = organization.id; - this.organization.orgName = organization.orgName; - this.organization.name = organization.name; - this.organization.tagline = organization.tagline; - this.organization.iconUrl = organization.iconUrl; + if (status.value === "success") { + const organization = data.value!; + this.organization.id = organization.id; + this.organization.orgName = organization.orgName; + this.organization.name = organization.name; + this.organization.tagline = organization.tagline; + this.organization.iconUrl = organization.iconUrl; - this.organization.location = organization.location; + this.organization.location = organization.location; - this.organization.getInvolvedUrl = organization.getInvolvedUrl; - this.organization.socialLinks = organization.socialLinks; - this.organization.status = organization.status; + this.organization.getInvolvedUrl = organization.getInvolvedUrl; + this.organization.socialLinks = organization.socialLinks; + this.organization.status = organization.status; - this.organization.organizationTextId = organization.texts.orgId; - this.organization.texts = organization.texts; + this.organization.organizationTextId = organization.texts.orgId; + this.organization.texts = organization.texts; - this.organization.groups = organization.groups; + this.organization.groups = organization.groups; + } this.loading = false; }, @@ -124,14 +127,16 @@ export const useOrganizationStore = defineStore("organization", { async fetchAll() { this.loading = true; - const responseOrgs = await useAsyncData( - async () => await fetchWithoutToken(`/entities/organizations/`, {}) + const { data, status } = await useAsyncData( + async () => + (await fetchWithoutToken( + `/entities/organizations/`, + {} + )) as Organization[] ); - const orgs = responseOrgs.data as unknown as PiniaResOrganizations; - - if (orgs._value) { - const organizations = orgs._value.map((org: Organization) => { + if (status.value === "success") { + const organizations = data.value!.map((org: Organization) => { return { id: org.id, orgName: org.orgName,