E5VPWWBUPZF2IQQC4MVIF3T2G5IHQYONHR3NHIBKGGV3JEF7TDAQC C4PJ5BYCHKYQVPCXNESI5AZELV3TXCWXIVU7IFJ2F3MZVR23SQ3AC OBXY6BHNROIV7W4O3MMQ6GTQXU2XUKF5A4DCJYDLUEUHV72E7BNAC U4CVCPSGPGYWJ4PA72HHHCHKJSQW3GU2QFK4YFSMKQOEM2MMY3PQC 4M3EBLTLSS2BRCM42ZP7WVD4YMRRLGV2P2XF47IAV5XHHJD52HTQC OWHNUYOKSGQTG6ZSVQZ3DNMYCW3IOEMXGRRS5QRRDAPIG4MOODNAC EUEH65HBT4XZXCNWECJXNDEQAWR2NLNSAXFPXLMQ27NOVMQBJT5QC NYBASAG4KWZNPSFBXWQJWQRBCGT7C5B24IYO2IBCXCE2WGJQJOEQC VFENVAHOAERPOWJFWVQBS5GXK3F422I62ZGQGOJHALKZZK2Q2SJAC LSAQ6ZM2NELU3FIWKEFBOXKVLSZS2ZOK2PHPHJRWPVZ5CVILSUYQC // Validate latitude and longitude if providedif (latitude !== null && latitude !== undefined) {const lat = Number(latitude);if (isNaN(lat) || lat < -90 || lat > 90) {return c.json({error: "Field 'latitude' must be a valid number between -90 and 90"}, 400);}
// Validate latitude and longitude (now required)if (latitude === null || latitude === undefined || latitude === '') {return c.json({error: "Missing required field: latitude"}, 400);
if (longitude !== null && longitude !== undefined) {const lng = Number(longitude);if (isNaN(lng) || lng < -180 || lng > 180) {return c.json({error: "Field 'longitude' must be a valid number between -180 and 180"}, 400);}
if (longitude === null || longitude === undefined || longitude === '') {return c.json({error: "Missing required field: longitude"}, 400);}const lat = Number(latitude);if (isNaN(lat) || lat < -90 || lat > 90) {return c.json({error: "Field 'latitude' must be a valid number between -90 and 90"}, 400);}const lng = Number(longitude);if (isNaN(lng) || lng < -180 || lng > 180) {return c.json({error: "Field 'longitude' must be a valid number between -180 and 180"}, 400);
latitude: latitude !== null && latitude !== undefined ? String(Number(latitude)) : null,longitude: longitude !== null && longitude !== undefined ? String(Number(longitude)) : null,
latitude: String(Number(latitude)),longitude: String(Number(longitude)),
// Validate and add latitude if providedif (latitude !== undefined) {if (latitude !== null) {const lat = Number(latitude);if (isNaN(lat) || lat < -90 || lat > 90) {return c.json({error: "Field 'latitude' must be a valid number between -90 and 90"}, 400);}updateData.latitude = String(lat);} else {updateData.latitude = null;
// Validate coordinates - both latitude and longitude are now required togetherif (latitude !== undefined || longitude !== undefined) {// If updating coordinates, both must be providedif (latitude === undefined || longitude === undefined) {return c.json({error: "Both latitude and longitude must be provided together"}, 400);}// Both must be valid numbers, not nullif (latitude === null || latitude === undefined || latitude === '') {return c.json({error: "Field 'latitude' is required and cannot be null"}, 400);}if (longitude === null || longitude === undefined || longitude === '') {return c.json({error: "Field 'longitude' is required and cannot be null"}, 400);}const lat = Number(latitude);if (isNaN(lat) || lat < -90 || lat > 90) {return c.json({error: "Field 'latitude' must be a valid number between -90 and 90"}, 400);
// Validate and add longitude if providedif (longitude !== undefined) {if (longitude !== null) {const lng = Number(longitude);if (isNaN(lng) || lng < -180 || lng > 180) {return c.json({error: "Field 'longitude' must be a valid number between -180 and 180"}, 400);}updateData.longitude = String(lng);} else {updateData.longitude = null;
const lng = Number(longitude);if (isNaN(lng) || lng < -180 || lng > 180) {return c.json({error: "Field 'longitude' must be a valid number between -180 and 180"}, 400);
latitude: decimal("latitude", { precision: 10, scale: 7 }), // -45.5027longitude: decimal("longitude", { precision: 10, scale: 7 }), // 167.48406
latitude: decimal("latitude", { precision: 10, scale: 7 }).notNull(), // -45.5027longitude: decimal("longitude", { precision: 10, scale: 7 }).notNull(), // 167.48406
latitude DECIMAL(10, 7) CHECK (latitude BETWEEN -90.0 AND 90.0), -- -45.5027longitude DECIMAL(10, 7) CHECK (longitude BETWEEN -180.0 AND 180.0), -- 167.48406
latitude DECIMAL(10, 7) NOT NULL CHECK (latitude BETWEEN -90.0 AND 90.0), -- -45.5027longitude DECIMAL(10, 7) NOT NULL CHECK (longitude BETWEEN -180.0 AND 180.0), -- 167.48406
-- Migration: Make latitude and longitude NOT NULL in location table-- This prevents the astronomical calculation issue where locations without coordinates-- cause AudioMoth files to miss moon_phase, maybe_solar_night, maybe_civil_night dataALTER TABLE location ALTER COLUMN latitude SET NOT NULL;ALTER TABLE location ALTER COLUMN longitude SET NOT NULL;SELECT NOW();-- 2025-06-28 22:36:47.431+00
"projectId":"wild-field-39453441"