trithuc-mvc-react 2.6.0 → 2.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/index.js +20 -12
- package/package.json +1 -1
package/api/index.js
CHANGED
|
@@ -58,7 +58,6 @@ export const getDatasFromTable = async ({ tableName, page, pageSize, data }) =>
|
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
|
-
|
|
62
61
|
return res.data;
|
|
63
62
|
} catch (error) {
|
|
64
63
|
console.error("Error fetching data:", error);
|
|
@@ -67,15 +66,24 @@ export const getDatasFromTable = async ({ tableName, page, pageSize, data }) =>
|
|
|
67
66
|
};
|
|
68
67
|
|
|
69
68
|
export const getDataFromTable = async ({ tableName, id }) => {
|
|
70
|
-
try {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
69
|
+
try {
|
|
70
|
+
if (!apiUrl) {
|
|
71
|
+
const url = `${getBaseUrl()}/Admin/${tableName}/GetDetail`;
|
|
72
|
+
const res = await api.get(url, {
|
|
73
|
+
params: {
|
|
74
|
+
id
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
return res.data;
|
|
78
|
+
}else{
|
|
79
|
+
const url = `${getBaseUrl()}/${apiUrl}/${tableName}/${id}`;
|
|
80
|
+
const res = await api.get(url, {
|
|
81
|
+
params: {
|
|
82
|
+
id
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
return res.data;
|
|
86
|
+
}
|
|
79
87
|
} catch (error) {
|
|
80
88
|
console.error("Error fetching data:", error);
|
|
81
89
|
throw error;
|
|
@@ -124,13 +132,13 @@ export const saveDataToTable = async ({ tableName, data }) => {
|
|
|
124
132
|
});
|
|
125
133
|
return res.data;
|
|
126
134
|
} else {
|
|
127
|
-
if (!data.
|
|
135
|
+
if (!data.Id) {
|
|
128
136
|
// Khi không có ID, thực hiện POST đến apiUrl
|
|
129
137
|
const res = await api.post(`${getBaseUrl()}/${apiUrl}/${tableName}`, data);
|
|
130
138
|
return res.data;
|
|
131
139
|
} else {
|
|
132
140
|
// Khi có ID, thực hiện PUT đến apiUrl với ID trong URL
|
|
133
|
-
const res = await api.put(`${getBaseUrl()}/${apiUrl}/${tableName}/${data.
|
|
141
|
+
const res = await api.put(`${getBaseUrl()}/${apiUrl}/${tableName}/${data.Id}`, data);
|
|
134
142
|
return res.data;
|
|
135
143
|
}
|
|
136
144
|
}
|