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>
167 lines
5.4 KiB
TypeScript
167 lines
5.4 KiB
TypeScript
import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'
|
|
import type { MaybeRef, Ref } from 'vue'
|
|
import { unref } from 'vue'
|
|
import { apiClient } from '@/lib/axios'
|
|
import type { AssignablePerson, AssignablePersonsMeta, ShiftAssignment } from '@/types/shiftAssignment'
|
|
|
|
interface ApiResponse<T> {
|
|
success: boolean
|
|
data: T
|
|
message?: string
|
|
}
|
|
|
|
interface PaginatedResponse<T> {
|
|
data: T[]
|
|
links: Record<string, string | null>
|
|
meta: {
|
|
current_page: number
|
|
per_page: number
|
|
total: number
|
|
last_page: number
|
|
}
|
|
}
|
|
|
|
export interface ShiftAssignmentFilters {
|
|
shift_id?: string
|
|
person_id?: string
|
|
section_id?: string
|
|
status?: string
|
|
}
|
|
|
|
export function useShiftAssignmentList(
|
|
orgId: Ref<string>,
|
|
eventId: Ref<string>,
|
|
filters?: Ref<ShiftAssignmentFilters>,
|
|
) {
|
|
return useQuery({
|
|
queryKey: ['shift-assignments', eventId, filters],
|
|
queryFn: async () => {
|
|
const params: Record<string, string> = {}
|
|
if (filters?.value?.shift_id) params.shift_id = filters.value.shift_id
|
|
if (filters?.value?.person_id) params.person_id = filters.value.person_id
|
|
if (filters?.value?.section_id) params.section_id = filters.value.section_id
|
|
if (filters?.value?.status) params.status = filters.value.status
|
|
|
|
const { data } = await apiClient.get<PaginatedResponse<ShiftAssignment>>(
|
|
`/organisations/${orgId.value}/events/${eventId.value}/shift-assignments`,
|
|
{ params },
|
|
)
|
|
|
|
return data
|
|
},
|
|
enabled: () => !!orgId.value && !!eventId.value,
|
|
})
|
|
}
|
|
|
|
export function useApproveAssignment(orgId: Ref<string>, eventId: Ref<string>) {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation({
|
|
mutationFn: async (assignmentId: string) => {
|
|
const { data } = await apiClient.post<ApiResponse<ShiftAssignment>>(
|
|
`/organisations/${orgId.value}/events/${eventId.value}/shift-assignments/${assignmentId}/approve`,
|
|
)
|
|
|
|
return data.data
|
|
},
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ['shift-assignments', eventId.value] })
|
|
queryClient.invalidateQueries({ queryKey: ['shifts'] })
|
|
},
|
|
})
|
|
}
|
|
|
|
export function useRejectAssignment(orgId: Ref<string>, eventId: Ref<string>) {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation({
|
|
mutationFn: async ({ assignmentId, reason }: { assignmentId: string; reason?: string }) => {
|
|
const { data } = await apiClient.post<ApiResponse<ShiftAssignment>>(
|
|
`/organisations/${orgId.value}/events/${eventId.value}/shift-assignments/${assignmentId}/reject`,
|
|
{ reason },
|
|
)
|
|
|
|
return data.data
|
|
},
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ['shift-assignments', eventId.value] })
|
|
queryClient.invalidateQueries({ queryKey: ['shifts'] })
|
|
},
|
|
})
|
|
}
|
|
|
|
export function useCancelAssignment(orgId: Ref<string>, eventId: Ref<string>) {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation({
|
|
mutationFn: async (assignmentId: string) => {
|
|
const { data } = await apiClient.post<ApiResponse<ShiftAssignment>>(
|
|
`/organisations/${orgId.value}/events/${eventId.value}/shift-assignments/${assignmentId}/cancel`,
|
|
)
|
|
|
|
return data.data
|
|
},
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ['shift-assignments', eventId.value] })
|
|
queryClient.invalidateQueries({ queryKey: ['shifts'] })
|
|
},
|
|
})
|
|
}
|
|
|
|
export function useBulkApproveAssignments(orgId: Ref<string>, eventId: Ref<string>) {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation({
|
|
mutationFn: async (assignmentIds: string[]) => {
|
|
const { data } = await apiClient.post<ApiResponse<unknown>>(
|
|
`/organisations/${orgId.value}/events/${eventId.value}/shift-assignments/bulk-approve`,
|
|
{ assignment_ids: assignmentIds },
|
|
)
|
|
|
|
return data.data
|
|
},
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ['shift-assignments', eventId.value] })
|
|
queryClient.invalidateQueries({ queryKey: ['shifts'] })
|
|
},
|
|
})
|
|
}
|
|
|
|
export function useAssignPersonToShift(orgId: Ref<string>, eventId: Ref<string>) {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation({
|
|
mutationFn: async ({ sectionId, shiftId, personId }: { sectionId: string; shiftId: string; personId: string }) => {
|
|
const { data } = await apiClient.post<ApiResponse<ShiftAssignment>>(
|
|
`/organisations/${orgId.value}/events/${eventId.value}/sections/${sectionId}/shifts/${shiftId}/assign`,
|
|
{ person_id: personId },
|
|
)
|
|
|
|
return data.data
|
|
},
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ['shift-assignments', eventId.value] })
|
|
queryClient.invalidateQueries({ queryKey: ['assignable-persons'] })
|
|
queryClient.invalidateQueries({ queryKey: ['shifts'] })
|
|
queryClient.invalidateQueries({ queryKey: ['persons', eventId.value] })
|
|
},
|
|
})
|
|
}
|
|
|
|
export function useAssignablePersons(orgId: MaybeRef<string>, eventId: MaybeRef<string>, shiftId: MaybeRef<string>) {
|
|
return useQuery({
|
|
queryKey: ['assignable-persons', eventId, shiftId],
|
|
queryFn: async () => {
|
|
const { data } = await apiClient.get<{ data: AssignablePerson[]; meta: AssignablePersonsMeta }>(
|
|
`/organisations/${unref(orgId)}/events/${unref(eventId)}/shifts/${unref(shiftId)}/assignable-persons`,
|
|
)
|
|
|
|
return {
|
|
persons: data.data,
|
|
meta: data.meta,
|
|
}
|
|
},
|
|
enabled: () => !!unref(orgId) && !!unref(eventId) && !!unref(shiftId),
|
|
})
|
|
}
|