Time Composable
This commit is contained in:
54
composables/useStaffTime.ts
Normal file
54
composables/useStaffTime.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
interface StaffTimeEntry {
|
||||
id: string
|
||||
started_at: string
|
||||
stopped_at?: string | null
|
||||
duration_minutes?: number | null
|
||||
type: string
|
||||
description?: string | null
|
||||
created_at?: string
|
||||
}
|
||||
|
||||
export function useStaffTime() {
|
||||
const { $api } = useNuxtApp()
|
||||
|
||||
|
||||
|
||||
async function list(params?: { user_id?: string }) {
|
||||
const query = new URLSearchParams()
|
||||
if (params?.user_id) query.append("user_id", params.user_id)
|
||||
|
||||
return await $api(`/api/staff/time${query.toString() ? `?${query}` : ''}`, { method: 'GET' })
|
||||
}
|
||||
|
||||
async function start(description?: string) {
|
||||
return await $api<StaffTimeEntry>('/api/staff/time', {
|
||||
method: 'POST',
|
||||
body: {
|
||||
started_at: new Date().toISOString(),
|
||||
type: 'work',
|
||||
description,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
async function stop(id: string) {
|
||||
return await $api<StaffTimeEntry>(`/api/staff/time/${id}/stop`, {
|
||||
method: 'PUT',
|
||||
body: { stopped_at: new Date().toISOString() },
|
||||
})
|
||||
}
|
||||
|
||||
async function get(id: string) {
|
||||
return await $api<StaffTimeEntry>(`/api/staff/time/${id}`, { method: 'GET' })
|
||||
}
|
||||
|
||||
async function create(data: Record<string, any>) {
|
||||
return await $api('/api/staff/time', { method: 'POST', body: data })
|
||||
}
|
||||
|
||||
async function update(id: string, data: Record<string, any>) {
|
||||
return await $api(`/api/staff/time/${id}`, { method: 'PUT', body: data })
|
||||
}
|
||||
|
||||
return { list, start, stop, get, create, update }
|
||||
}
|
||||
Reference in New Issue
Block a user