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>
131 lines
3.7 KiB
TypeScript
131 lines
3.7 KiB
TypeScript
import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'
|
|
import type { Ref } from 'vue'
|
|
import { apiClient } from '@/lib/axios'
|
|
import type { CreatePersonPayload, Person, UpdatePersonPayload } from '@/types/person'
|
|
|
|
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
|
|
total_approved: number
|
|
total_pending: number
|
|
total_rejected: number
|
|
}
|
|
}
|
|
|
|
export function usePersonList(
|
|
orgId: Ref<string>,
|
|
eventId: Ref<string>,
|
|
filters?: Ref<{ crowd_type_id?: string; status?: string }>,
|
|
) {
|
|
return useQuery({
|
|
queryKey: ['persons', eventId, filters],
|
|
queryFn: async () => {
|
|
const params: Record<string, string> = {}
|
|
if (filters?.value?.crowd_type_id)
|
|
params.crowd_type_id = filters.value.crowd_type_id
|
|
if (filters?.value?.status)
|
|
params.status = filters.value.status
|
|
|
|
const { data } = await apiClient.get<PaginatedResponse<Person>>(
|
|
`/organisations/${orgId.value}/events/${eventId.value}/persons`,
|
|
{ params },
|
|
)
|
|
|
|
return data
|
|
},
|
|
enabled: () => !!orgId.value && !!eventId.value,
|
|
})
|
|
}
|
|
|
|
export function usePersonDetail(orgId: Ref<string>, eventId: Ref<string>, id: Ref<string>) {
|
|
return useQuery({
|
|
queryKey: ['persons', eventId, 'detail', id],
|
|
queryFn: async () => {
|
|
const { data } = await apiClient.get<ApiResponse<Person>>(
|
|
`/organisations/${orgId.value}/events/${eventId.value}/persons/${id.value}`,
|
|
)
|
|
|
|
return data.data
|
|
},
|
|
enabled: () => !!orgId.value && !!eventId.value && !!id.value,
|
|
})
|
|
}
|
|
|
|
export function useCreatePerson(orgId: Ref<string>, eventId: Ref<string>) {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation({
|
|
mutationFn: async (payload: CreatePersonPayload) => {
|
|
const { data } = await apiClient.post<ApiResponse<Person>>(
|
|
`/organisations/${orgId.value}/events/${eventId.value}/persons`,
|
|
payload,
|
|
)
|
|
|
|
return data.data
|
|
},
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ['persons', eventId.value] })
|
|
},
|
|
})
|
|
}
|
|
|
|
export function useUpdatePerson(orgId: Ref<string>, eventId: Ref<string>) {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation({
|
|
mutationFn: async ({ id, ...payload }: UpdatePersonPayload & { id: string }) => {
|
|
const { data } = await apiClient.put<ApiResponse<Person>>(
|
|
`/organisations/${orgId.value}/events/${eventId.value}/persons/${id}`,
|
|
payload,
|
|
)
|
|
|
|
return data.data
|
|
},
|
|
onSuccess: (_data, variables) => {
|
|
queryClient.invalidateQueries({ queryKey: ['persons', eventId.value] })
|
|
queryClient.invalidateQueries({ queryKey: ['persons', eventId.value, 'detail', variables.id] })
|
|
},
|
|
})
|
|
}
|
|
|
|
export function useApprovePerson(orgId: Ref<string>, eventId: Ref<string>) {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation({
|
|
mutationFn: async (id: string) => {
|
|
const { data } = await apiClient.post<ApiResponse<Person>>(
|
|
`/organisations/${orgId.value}/events/${eventId.value}/persons/${id}/approve`,
|
|
)
|
|
|
|
return data.data
|
|
},
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ['persons', eventId.value] })
|
|
},
|
|
})
|
|
}
|
|
|
|
export function useDeletePerson(orgId: Ref<string>, eventId: Ref<string>) {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation({
|
|
mutationFn: async (id: string) => {
|
|
await apiClient.delete(`/organisations/${orgId.value}/events/${eventId.value}/persons/${id}`)
|
|
},
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ['persons', eventId.value] })
|
|
},
|
|
})
|
|
}
|