-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.ts
59 lines (53 loc) · 1.8 KB
/
api.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import axios from 'axios'
export const api = axios.create({
baseURL: localStorage.getItem('invoiceNinjaURL') || '',
headers: {
'x-api-token': localStorage.getItem('invoiceNinjaAPIToken')
}
})
api.interceptors.response.use((response) => {
return response.data
})
export const getClients = () => api.get('/clients?per_page=6&page=1?status=active&without_deleted=true&sort=number|desc')
export const getProjects = () => api.get('/projects?per_page=6&page=1?&status=active&without_deleted_clients=true&sort=budgeted_hours|desc')
export const getProject = (id: string) => api.get(`/projects/${id}`)
export const getTasks = ({
clientId,
projectId,
taskStatusId,
filter
}: {
clientId?: string
projectId: string | null
taskStatusId?: string
filter?: string
}) =>
api.get(`/tasks?without_deleted_clients=true&sort=number|desc&per_page=60&page=1&client_status=uninvoiced&status=active`, {
params: {
project_tasks: projectId,
client_id: clientId,
task_status: taskStatusId,
filter
}
})
export const getTask = (id: string) => api.get(`/tasks/${id}`)
export const putTask = (
id: string,
{
action,
data
}: {
action?: string
data?: any
}
) =>
api.put(`/tasks/${id}`, data, {
params: {
...(action && {[action]: true})
}
})
export const postTask = ({description, projectId}: {description: string; projectId: string}) =>
api.post(`/tasks`, {description, project_id: projectId})
export const deleteTask = (id: string) => api.delete(`/tasks/${id}`)
export const getTaskStatuses = () => api.get('/task_statuses')
export const addTaskStatus = (data: {name: string; color: string; task_status_order: number}) => api.post('/task_statuses', data)