a few more dashboard updates
This commit is contained in:
@@ -46,6 +46,53 @@ class NocoDBService {
|
||||
const response = await this.client.get(url, { params });
|
||||
return response.data;
|
||||
}
|
||||
|
||||
// Get ALL records from a table using pagination
|
||||
async getAllPaginated(tableId, params = {}) {
|
||||
try {
|
||||
let allRecords = [];
|
||||
let offset = 0;
|
||||
const limit = params.limit || 100;
|
||||
let hasMore = true;
|
||||
|
||||
while (hasMore) {
|
||||
const response = await this.getAll(tableId, {
|
||||
...params,
|
||||
limit: limit,
|
||||
offset: offset
|
||||
});
|
||||
|
||||
const records = response.list || [];
|
||||
allRecords = allRecords.concat(records);
|
||||
|
||||
// Check if there are more records
|
||||
hasMore = records.length === limit;
|
||||
offset += limit;
|
||||
|
||||
// Safety check to prevent infinite loops
|
||||
if (offset > 10000) {
|
||||
logger.warn(`Reached maximum offset limit while fetching records from table ${tableId}`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
logger.info(`Fetched ${allRecords.length} total records from table ${tableId}`);
|
||||
|
||||
return {
|
||||
list: allRecords,
|
||||
pageInfo: {
|
||||
totalRows: allRecords.length,
|
||||
page: 1,
|
||||
pageSize: allRecords.length,
|
||||
isFirstPage: true,
|
||||
isLastPage: true
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
logger.error('Error fetching paginated records:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// Get single record
|
||||
async getById(tableId, recordId) {
|
||||
@@ -77,6 +124,12 @@ class NocoDBService {
|
||||
|
||||
// Get locations with proper filtering
|
||||
async getLocations(params = {}) {
|
||||
// For locations, we want all records by default, so use getAllPaginated
|
||||
// unless specific limit/offset are provided
|
||||
if (!params.limit && !params.offset) {
|
||||
return this.getAllPaginated(config.nocodb.tableId, params);
|
||||
}
|
||||
|
||||
const defaultParams = {
|
||||
limit: 1000,
|
||||
offset: 0,
|
||||
|
||||
Reference in New Issue
Block a user