Files
tp/main_dc/yalarba/easySite/app/composables/useObjects.ts
T
valitovgaziz 2941b14b38 flatten easySite directory: remove extra easySite/easySite nesting
- Moved contents of main_dc/yalarba/easySite/easySite/ up to easySite/
- Updated docker-compose.yml build context path
- Deleted empty nested easySite/ directory
2026-06-12 11:16:15 +05:00

88 lines
2.0 KiB
TypeScript

import type {
ObjectShortResponse,
ObjectResponse,
ObjectListResponse,
CreateObjectRequest,
UpdateObjectRequest
} from '~/types/objects'
export const useObjects = () => {
const config = useRuntimeConfig()
const apiBase = config.public.apiBase
const getAuthHeaders = () => {
const token = localStorage.getItem('auth_token')
return token ? { Authorization: `Bearer ${token}` } : {}
}
const getList = async (params?: {
page?: number
page_size?: number
type?: string
q?: string
status?: string
is_active?: boolean
}) => {
return $fetch<ObjectListResponse>(`${apiBase}/objects`, {
params
})
}
const getById = async (id: number) => {
return $fetch<ObjectResponse>(`${apiBase}/objects/${id}`)
}
const getMy = async (params?: { page?: number; page_size?: number; status?: string }) => {
return $fetch<ObjectListResponse>(`${apiBase}/objects/my`, {
headers: getAuthHeaders(),
params
})
}
const getByOwner = async (ownerId: number, params?: { page?: number; page_size?: number }) => {
return $fetch<ObjectListResponse>(`${apiBase}/objects/owner/${ownerId}`, {
params
})
}
const search = async (q: string, params?: { page?: number; page_size?: number }) => {
return $fetch<ObjectListResponse>(`${apiBase}/objects/search`, {
params: { q, ...params }
})
}
const create = async (data: CreateObjectRequest) => {
return $fetch<ObjectResponse>(`${apiBase}/objects`, {
method: 'POST',
headers: getAuthHeaders(),
body: data
})
}
const update = async (id: number, data: UpdateObjectRequest) => {
return $fetch<ObjectResponse>(`${apiBase}/objects/${id}`, {
method: 'PUT',
headers: getAuthHeaders(),
body: data
})
}
const remove = async (id: number) => {
return $fetch<void>(`${apiBase}/objects/${id}`, {
method: 'DELETE',
headers: getAuthHeaders()
})
}
return {
getList,
getById,
getMy,
getByOwner,
search,
create,
update,
remove
}
}