Files
crewli/apps/app/src/composables/api/useShifts.ts
bert.hausmans 7932e53daf security: A01-13 — nest all event routes under organisation prefix
Move all authenticated organiser-facing event sub-resource routes from
/events/{event}/... to /organisations/{organisation}/events/{event}/...
to enforce multi-tenancy at the routing layer.

Changes:
- Routes: restructured api.php to nest all event sub-resources under
  the existing organisation prefix group
- Controllers: added Organisation parameter and VerifiesOrganisationEvent
  trait to all 12 affected controllers (sections, time-slots, shifts,
  persons, crowd-lists, locations, shift-assignments, registration-fields,
  availabilities, field-values, section-preferences, stats)
- Tests: updated all 20 feature test files with new route paths
- Frontend: updated 8 API composables and 20 Vue components/pages
- API.md: updated documentation to reflect new route structure

Portal routes, public routes (volunteer-register), and invitation routes
remain unchanged as they operate without organisation context.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 08:16:36 +02:00

99 lines
3.1 KiB
TypeScript

import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'
import type { Ref } from 'vue'
import { apiClient } from '@/lib/axios'
import type { CreateShiftPayload, Shift, UpdateShiftPayload } from '@/types/section'
interface ApiResponse<T> {
success: boolean
data: T
message?: string
}
interface PaginatedResponse<T> {
data: T[]
}
export function useShiftList(orgId: Ref<string>, eventId: Ref<string>, sectionId: Ref<string>) {
return useQuery({
queryKey: ['shifts', sectionId],
queryFn: async () => {
const { data } = await apiClient.get<PaginatedResponse<Shift>>(
`/organisations/${orgId.value}/events/${eventId.value}/sections/${sectionId.value}/shifts`,
)
return data.data
},
enabled: () => !!orgId.value && !!eventId.value && !!sectionId.value,
})
}
export function useCreateShift(orgId: Ref<string>, eventId: Ref<string>, sectionId: Ref<string>) {
const queryClient = useQueryClient()
return useMutation({
mutationFn: async (payload: CreateShiftPayload) => {
const { data } = await apiClient.post<ApiResponse<Shift>>(
`/organisations/${orgId.value}/events/${eventId.value}/sections/${sectionId.value}/shifts`,
payload,
)
return data.data
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['shifts', sectionId.value] })
},
})
}
export function useUpdateShift(orgId: Ref<string>, eventId: Ref<string>, sectionId: Ref<string>) {
const queryClient = useQueryClient()
return useMutation({
mutationFn: async ({ id, ...payload }: UpdateShiftPayload & { id: string }) => {
const { data } = await apiClient.put<ApiResponse<Shift>>(
`/organisations/${orgId.value}/events/${eventId.value}/sections/${sectionId.value}/shifts/${id}`,
payload,
)
return data.data
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['shifts', sectionId.value] })
},
})
}
export function useDeleteShift(orgId: Ref<string>, eventId: Ref<string>, sectionId: Ref<string>) {
const queryClient = useQueryClient()
return useMutation({
mutationFn: async (id: string) => {
await apiClient.delete(
`/organisations/${orgId.value}/events/${eventId.value}/sections/${sectionId.value}/shifts/${id}`,
)
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['shifts', sectionId.value] })
},
})
}
export function useAssignShift(orgId: Ref<string>, eventId: Ref<string>, sectionId: Ref<string>) {
const queryClient = useQueryClient()
return useMutation({
mutationFn: async ({ shiftId, personId }: { shiftId: string; personId: string }) => {
const { data } = await apiClient.post<ApiResponse<unknown>>(
`/organisations/${orgId.value}/events/${eventId.value}/sections/${sectionId.value}/shifts/${shiftId}/assign`,
{ person_id: personId },
)
return data.data
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['shifts', sectionId.value] })
queryClient.invalidateQueries({ queryKey: ['persons', eventId.value] })
},
})
}