Create or Update Gas Readings
Route: POST /api/gas-readings
Functionality:
Insert or update a gas reading for a specific sensor.
Service Layer (
services/gasReadingService.js):
// javascript
import { db } from '@/lib/db';
export async function updateGasReading(sensorId, clientId, gasLevel) {
let status = 'Normal';
if (gasLevel <= 20) status = 'Low';
else if (gasLevel > 80) status = 'High';
return await db.gasReading.upsert({
where: { sensor_id: sensorId },
update: { gas_level: gasLevel, status, last_updated: new Date() },
create: {
sensor_id: sensorId,
client_id: clientId,
gas_level: gasLevel,
status,
location: { lat: 0, lng: 0 },
},
});
}
Last updated