refactor org id handling in mutations to make it more robust

This commit is contained in:
Gregor Vostrak
2026-04-07 18:14:21 +02:00
parent 93b31d6f0f
commit fb54ec02db
4 changed files with 22 additions and 19 deletions
+1 -3
View File
@@ -284,9 +284,7 @@ const totalTime = computed(() => {
class="flex items-center justify-center py-12">
<div class="text-center text-text-tertiary">
<p class="text-lg">No activity data available</p>
<p class="text-sm mt-2">
Check back in a few minutes
</p>
<p class="text-sm mt-2">Check back in a few minutes</p>
</div>
</div>
+1
View File
@@ -14,6 +14,7 @@ export function useMyMemberships() {
const query = useQuery({
queryKey: ['myMemberships'],
queryFn: getMyMemberships,
gcTime: Infinity,
})
const memberships = computed<MyMemberships>(() => {
return query.data.value?.data ?? []
+16 -15
View File
@@ -93,8 +93,8 @@ export function useTimeEntryStopMutation() {
id: 'timeEntry',
},
mutationFn: (timeEntry: TimeEntry) => {
if (currentOrganizationId.value === null) {
throw new Error('No current organization id - create time entry')
if (!timeEntry.organization_id) {
throw new Error('No organization id on time entry - stop time entry')
}
if (timeEntry.id === '') {
throw new Error('No time entry id - stop time entry')
@@ -106,7 +106,7 @@ export function useTimeEntryStopMutation() {
{ ...timeEntry },
{
params: {
organization: currentOrganizationId.value,
organization: timeEntry.organization_id,
timeEntry: timeEntry.id,
},
}
@@ -138,8 +138,8 @@ export function useTimeEntryUpdateMutation() {
mutationFn: (timeEntry: TimeEntry) => {
console.log('update time entry')
console.log(timeEntry)
if (currentOrganizationId.value === null) {
throw new Error('No current organization id - update time entry')
if (!timeEntry.organization_id) {
throw new Error('No organization id on time entry - update time entry')
}
if (timeEntry.id === '') {
throw new Error('No time entry id - update time entry')
@@ -149,7 +149,7 @@ export function useTimeEntryUpdateMutation() {
}
return apiClient.value.updateTimeEntry(timeEntry, {
params: {
organization: currentOrganizationId.value,
organization: timeEntry.organization_id,
timeEntry: timeEntry.id,
},
})
@@ -189,8 +189,9 @@ export function useTimeEntriesDeleteMutation() {
id: 'timeEntry',
},
mutationFn: (timeEntries: TimeEntry[]) => {
if (currentOrganizationId.value === null) {
throw new Error('No current organization id - create time entry')
const organizationId = timeEntries[0].organization_id
if (!organizationId) {
throw new Error('No organization id on time entry - delete time entries')
}
const timeEntryIds = timeEntries.map((timeEntry) => {
if (offlineUuidStore[timeEntry.id]) {
@@ -203,7 +204,7 @@ export function useTimeEntriesDeleteMutation() {
ids: timeEntryIds,
},
params: {
organization: currentOrganizationId.value,
organization: organizationId,
},
})
},
@@ -273,8 +274,8 @@ export function useCurrentTimeEntryUpdateMutation() {
id: 'timeEntry',
},
mutationFn: (timeEntry: TimeEntry) => {
if (currentOrganizationId.value === null) {
throw new Error('No current organization id - update time entry')
if (!timeEntry.organization_id) {
throw new Error('No organization id on time entry - update time entry')
}
if (timeEntry.id === '') {
throw new Error('No time entry id - update time entry')
@@ -284,7 +285,7 @@ export function useCurrentTimeEntryUpdateMutation() {
}
return apiClient.value.updateTimeEntry(timeEntry, {
params: {
organization: currentOrganizationId.value,
organization: timeEntry.organization_id,
timeEntry: timeEntry.id,
},
})
@@ -311,15 +312,15 @@ export function useTimeEntryDeleteMutation() {
id: 'timeEntry',
},
mutationFn: (timeEntry: TimeEntry) => {
if (currentOrganizationId.value === null) {
throw new Error('No current organization id - create time entry')
if (!timeEntry.organization_id) {
throw new Error('No organization id on time entry - delete time entry')
}
if (offlineUuidStore[timeEntry.id]) {
timeEntry.id = offlineUuidStore[timeEntry.id]
}
return apiClient.value.deleteTimeEntry(undefined, {
params: {
organization: currentOrganizationId.value,
organization: timeEntry.organization_id,
timeEntry: timeEntry.id,
},
})
+4 -1
View File
@@ -53,9 +53,12 @@ export function useTimer() {
*/
async function stopTimer(endTime?: string) {
const stoppedTimeEntry = { ...currentTimeEntry.value }
currentMembershipId.value = memberships.value.find(
const matchingMembershipId = memberships.value.find(
(membership) => membership.organization.id === stoppedTimeEntry.organization_id
)?.id
if (matchingMembershipId) {
currentMembershipId.value = matchingMembershipId
}
currentTimeEntry.value = { ...emptyTimeEntry }
await timeEntryStop.mutateAsync({