update: enhance device API functions with pagination and response structure; modify device form validation and UI components

This commit is contained in:
2025-10-01 14:33:55 +07:00
parent 2778c96143
commit 3b51f59679
4 changed files with 353 additions and 224 deletions

View File

@@ -5,7 +5,39 @@ const getAllDevice = async (queryParams) => {
method: 'get',
prefix: `device?${queryParams.toString()}`,
});
return response;
console.log('getAllDevice response:', response);
console.log('Query params:', queryParams.toString());
// Parse query params to get page and limit
const params = Object.fromEntries(queryParams);
const currentPage = parseInt(params.page) || 1;
const currentLimit = parseInt(params.limit) || 10;
// Backend returns all data, so we need to do client-side pagination
const allData = response.data || [];
const totalData = allData.length;
// Calculate start and end index for current page
const startIndex = (currentPage - 1) * currentLimit;
const endIndex = startIndex + currentLimit;
// Slice data for current page
const paginatedData = allData.slice(startIndex, endIndex);
// Transform response to match TableList expected structure
return {
status: response.statusCode || 200,
data: {
data: paginatedData,
paging: {
page: currentPage,
limit: currentLimit,
total: totalData,
page_total: Math.ceil(totalData / currentLimit)
},
total: totalData
}
};
};
const getDeviceById = async (id) => {
@@ -22,7 +54,13 @@ const createDevice = async (queryParams) => {
prefix: `device`,
params: queryParams,
});
return response.data;
console.log('createDevice full response:', response);
// Return full response with statusCode
return {
statusCode: response.statusCode || 200,
data: response.data,
message: response.message
};
};
const updateDevice = async (device_id, queryParams) => {
@@ -31,7 +69,13 @@ const updateDevice = async (device_id, queryParams) => {
prefix: `device/${device_id}`,
params: queryParams,
});
return response.data;
console.log('updateDevice full response:', response);
// Return full response with statusCode
return {
statusCode: response.statusCode || 200,
data: response.data,
message: response.message
};
};
const deleteDevice = async (queryParams) => {
@@ -39,7 +83,13 @@ const deleteDevice = async (queryParams) => {
method: 'delete',
prefix: `device/${queryParams}`,
});
return response.data;
console.log('deleteDevice full response:', response);
// Return full response with statusCode
return {
statusCode: response.statusCode || 200,
data: response.data,
message: response.message
};
};
export { getAllDevice, getDeviceById, createDevice, updateDevice, deleteDevice };