-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapiService.ts
More file actions
87 lines (79 loc) · 2.16 KB
/
apiService.ts
File metadata and controls
87 lines (79 loc) · 2.16 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Author: Cotrax
* this file for Managing API calls and responses
*/
import axios from "axios";
import { Projects, Files, Time_Logs } from "../models/models";
// this base URL can be changed to yours
const apiClient = axios.create({
baseURL: "https://cotrax.onrender.com/api/v1", // "https://cotrax.onrender.com/api/v1" or "http://localhost:7000/api/v1"
timeout: 10000,
headers: {
"Content-Type": "application/json",
},
});
export const createProject = async (projectData: {
project_name: string;
project_path: string;
}): Promise<Projects> => {
try {
const response = await apiClient.post("/projects", projectData);
return response.data.data;
} catch (error) {
console.error("Error creating project:", error);
throw error;
}
};
export const getAllProjects = async (): Promise<Projects[]> => {
try {
const response = await apiClient.get("/projects");
return response.data.data;
} catch (error) {
console.error("Error fetching projects:", error);
throw error;
}
};
export const createFile = async (fileData: {
project_id: number;
filename: string;
filepath: string;
}): Promise<Files> => {
try {
const response = await apiClient.post("/files", fileData);
return response.data.data;
} catch (error) {
console.error("Error creating file:", error);
throw error;
}
};
export const getAllFiles = async (): Promise<Files[]> => {
try {
const response = await apiClient.get("/files");
return response.data.data;
} catch (error) {
console.error("Error fetching files:", error);
throw error;
}
};
export const createTimeLog = async (logData: {
file_id: number;
start_time: string;
end_time: string;
}): Promise<Time_Logs> => {
try {
const response = await apiClient.post("/time_logs", logData);
return response.data.data;
} catch (error) {
console.error("Error creating time log:", error);
throw error;
}
};
export const getAllTimeLogs = async (): Promise<Time_Logs[]> => {
try {
const response = await apiClient.get("/time_logs");
return response.data.data;
} catch (error) {
console.error("Error fetching time logs:", error);
throw error;
}
};