Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

router.js do not load all entities, when Id is missing #6535

Merged
merged 2 commits into from
Dec 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 50 additions & 18 deletions frontend/src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -704,35 +704,59 @@ async function requireChecklist(to, from, next) {
}

export function campFromRoute(route) {
return apiStore.get().camps({ id: route.params.campId })
if (route.params.campId) {
pmattmann marked this conversation as resolved.
Show resolved Hide resolved
return apiStore.get().camps({ id: route.params.campId })
} else {
return undefined
}
}

export function invitationFromInviteKey(inviteKey) {
return apiStore.get().invitations({ action: 'find', id: inviteKey })
}

export function periodFromRoute(route) {
return apiStore.get().periods({ id: route.params.periodId })
if (route.params.periodId) {
return apiStore.get().periods({ id: route.params.periodId })
} else {
return undefined
}
}

function scheduleEntryFromRoute(route) {
return apiStore.get().scheduleEntries({ id: route.params.scheduleEntryId })
if (route.params.scheduleEntryId) {
return apiStore.get().scheduleEntries({ id: route.params.scheduleEntryId })
} else {
return undefined
}
}

function categoryFromRoute(route) {
return campFromRoute(route)
.categories()
.allItems.find((c) => c.id === route.params.categoryId)
if (route.params.categoryId) {
return campFromRoute(route)
.categories()
.allItems.find((c) => c.id === route.params.categoryId)
} else {
return undefined
}
}

export function materialListFromRoute(route) {
return apiStore.get().materialLists({ id: route.params.materialId })
if (route.params.materialId) {
return apiStore.get().materialLists({ id: route.params.materialId })
} else {
return undefined
}
}

export function checklistFromRoute(route) {
return campFromRoute(route)
.checklists()
.allItems.find((c) => c.id === route.params.checklistId)
if (route.params.checklistId) {
return campFromRoute(route)
.checklists()
.allItems.find((c) => c.id === route.params.checklistId)
} else {
return undefined
}
}

function getContentLayout(route) {
Expand All @@ -755,7 +779,11 @@ function getContentLayout(route) {
}

function dayFromScheduleEntryInRoute(route) {
return apiStore.get().scheduleEntries({ id: route.params.scheduleEntryId }).day()
if (route.params.scheduleEntryId) {
return apiStore.get().scheduleEntries({ id: route.params.scheduleEntryId }).day()
} else {
return undefined
}
}

/**
Expand Down Expand Up @@ -934,13 +962,17 @@ export function checklistOverviewRoute(camp, checklist, query = {}) {
}

async function firstFuturePeriod(route) {
const periods = await apiStore.get().camps({ id: route.params.campId }).periods()._meta
.load
// Return the first period that hasn't ended, or if no such period exists, return the first period
return (
periods.items.find((period) => new Date(period.end) >= new Date()) ||
periods.items.find((_) => true)
)
if (route.params.campId) {
const periods = await apiStore.get().camps({ id: route.params.campId }).periods()
._meta.load
// Return the first period that hasn't ended, or if no such period exists, return the first period
return (
periods.items.find((period) => new Date(period.end) >= new Date()) ||
periods.items.find((_) => true)
)
} else {
return undefined
}
}

async function redirectToPeriod(to, from, next, routeName) {
Expand Down
Loading