debugged build precision values on decimal places inside nocodb

This commit is contained in:
admin 2025-07-11 10:00:37 -06:00
parent 08782379ab
commit 2b05b608ba
5 changed files with 82 additions and 55 deletions

View File

@ -121,10 +121,10 @@ class LocationsController {
}
}
// Format geodata
// Format geodata with string values to preserve precision
const geodata = `${validation.latitude};${validation.longitude}`;
// Prepare data for NocoDB
// Prepare data for NocoDB - keep coordinates as strings
const finalData = {
geodata,
'Geo-Location': geodata,

View File

@ -36,8 +36,8 @@ setInterval(() => {
* @returns {Promise<Object>} Geocoding result
*/
async function reverseGeocode(lat, lng) {
// Create cache key
const cacheKey = `${lat.toFixed(6)},${lng.toFixed(6)}`;
// Create cache key - use full precision
const cacheKey = `${lat},${lng}`;
// Check cache first
const cached = geocodeCache.get(cacheKey);

View File

@ -2,12 +2,16 @@
function syncGeoFields(data) {
// If we have latitude and longitude but no Geo-Location, create it
if (data.latitude && data.longitude && !data['Geo-Location']) {
const lat = parseFloat(data.latitude);
const lng = parseFloat(data.longitude);
if (!isNaN(lat) && !isNaN(lng)) {
// Keep as strings to preserve precision
const lat = typeof data.latitude === 'string' ? data.latitude : String(data.latitude);
const lng = typeof data.longitude === 'string' ? data.longitude : String(data.longitude);
data['Geo-Location'] = `${lat};${lng}`;
data.geodata = `${lat};${lng}`;
}
// Keep original values without parsing
data.latitude = lat;
data.longitude = lng;
}
// If we have Geo-Location but no lat/lng, parse it
else if (data['Geo-Location'] && (!data.latitude || !data.longitude)) {
@ -16,9 +20,12 @@ function syncGeoFields(data) {
// Try semicolon-separated first
let parts = geoLocation.split(';');
if (parts.length === 2) {
const lat = parseFloat(parts[0].trim());
const lng = parseFloat(parts[1].trim());
if (!isNaN(lat) && !isNaN(lng)) {
// Keep as strings to preserve precision
const lat = parts[0].trim();
const lng = parts[1].trim();
// Only validate they're numeric, don't convert
if (!isNaN(parseFloat(lat)) && !isNaN(parseFloat(lng))) {
data.latitude = lat;
data.longitude = lng;
data.geodata = `${lat};${lng}`;
@ -29,9 +36,10 @@ function syncGeoFields(data) {
// Try comma-separated
parts = geoLocation.split(',');
if (parts.length === 2) {
const lat = parseFloat(parts[0].trim());
const lng = parseFloat(parts[1].trim());
if (!isNaN(lat) && !isNaN(lng)) {
const lat = parts[0].trim();
const lng = parts[1].trim();
if (!isNaN(parseFloat(lat)) && !isNaN(parseFloat(lng))) {
data.latitude = lat;
data.longitude = lng;
data.geodata = `${lat};${lng}`;
@ -44,6 +52,46 @@ function syncGeoFields(data) {
return data;
}
// Validate coordinates
function validateCoordinates(lat, lng) {
// Keep original string values
const latStr = typeof lat === 'string' ? lat : String(lat);
const lngStr = typeof lng === 'string' ? lng : String(lng);
// Parse only for validation
const latitude = parseFloat(latStr);
const longitude = parseFloat(lngStr);
if (isNaN(latitude) || isNaN(longitude)) {
return { valid: false, error: 'Invalid coordinate values' };
}
if (latitude < -90 || latitude > 90) {
return { valid: false, error: 'Latitude must be between -90 and 90' };
}
if (longitude < -180 || longitude > 180) {
return { valid: false, error: 'Longitude must be between -180 and 180' };
}
// Return the original string values to preserve precision
return { valid: true, latitude: latStr, longitude: lngStr };
}
// Check if coordinates are within bounds
function checkBounds(lat, lng, bounds) {
if (!bounds) return true;
// Parse only for comparison
const latitude = parseFloat(lat);
const longitude = parseFloat(lng);
return latitude <= bounds.north &&
latitude >= bounds.south &&
longitude <= bounds.east &&
longitude >= bounds.west;
}
// Validate URL format
function validateUrl(url) {
if (!url || typeof url !== 'string') {
@ -101,36 +149,6 @@ function extractId(record) {
return record.Id || record.id || record.ID || record._id;
}
// Validate coordinates
function validateCoordinates(lat, lng) {
const latitude = parseFloat(lat);
const longitude = parseFloat(lng);
if (isNaN(latitude) || isNaN(longitude)) {
return { valid: false, error: 'Invalid coordinate values' };
}
if (latitude < -90 || latitude > 90) {
return { valid: false, error: 'Latitude must be between -90 and 90' };
}
if (longitude < -180 || longitude > 180) {
return { valid: false, error: 'Longitude must be between -180 and 180' };
}
return { valid: true, latitude, longitude };
}
// Check if coordinates are within bounds
function checkBounds(lat, lng, bounds) {
if (!bounds) return true;
return lat <= bounds.north &&
lat >= bounds.south &&
lng <= bounds.east &&
lng >= bounds.west;
}
// Sanitize user data for response
function sanitizeUser(user) {
const { Password, password, ...safeUser } = user;

View File

@ -265,16 +265,20 @@ create_locations_table() {
"title": "latitude",
"uidt": "Decimal",
"rqd": false,
"precision": 10,
"meta": {
"precision": 8,
"scale": 8
}
},
{
"column_name": "longitude",
"title": "longitude",
"uidt": "Decimal",
"rqd": false,
"precision": 11,
"meta": {
"precision": 8,
"scale": 8
}
},
{
"column_name": "first_name",
@ -486,16 +490,20 @@ create_settings_table() {
"title": "latitude",
"uidt": "Decimal",
"rqd": false,
"precision": 10,
"meta": {
"precision": 8,
"scale": 8
}
},
{
"column_name": "longitude",
"title": "longitude",
"uidt": "Decimal",
"rqd": false,
"precision": 11,
"meta": {
"precision": 8,
"scale": 8
}
},
{
"column_name": "zoom",

1
test.md Normal file
View File

@ -0,0 +1 @@
Just a test file