Skip to content

Commit

Permalink
fix: fixes some issues loading data
Browse files Browse the repository at this point in the history
  • Loading branch information
cquinn540 committed Dec 11, 2024
1 parent a56ef26 commit 5f466c7
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 79 deletions.
4 changes: 3 additions & 1 deletion backend/entities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions backend/entities/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions frontend/components/feed/Feed.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ const feedItemNames = computed<string[]>(() => {
const feedItemUrls = computed<string[]>(() => {
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 [""];
Expand Down
4 changes: 2 additions & 2 deletions frontend/composables/useLinkURL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
46 changes: 21 additions & 25 deletions frontend/stores/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import type {
Event,
EventCreateFormData,
EventUpdateTextFormData,
PiniaResEvent,
PiniaResEvents,
} from "~/types/events/event";

interface EventStore {
Expand Down Expand Up @@ -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<Event>(
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;
},
Expand All @@ -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<Event[]>(
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,
Expand Down
45 changes: 21 additions & 24 deletions frontend/stores/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import type {
Group,
GroupCreateFormData,
GroupUpdateTextFormData,
PiniaResGroup,
PiniaResGroups,
} from "~/types/entities/group";

interface GroupStore {
Expand Down Expand Up @@ -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<Group>(
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;
},
Expand All @@ -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<Group[]>(
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,
Expand Down
55 changes: 30 additions & 25 deletions frontend/stores/organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import type {
Organization,
OrganizationCreateFormData,
OrganizationUpdateTextFormData,
PiniaResOrganization,
PiniaResOrganizations,
} from "~/types/entities/organization";

interface OrganizationStore {
Expand Down Expand Up @@ -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<Organization>(
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;
},
Expand All @@ -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<Organization[]>(
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,
Expand Down

0 comments on commit 5f466c7

Please sign in to comment.