Update Sensor Status

Route: PATCH /api/sensors/:id/status

  • Functionality:

    • Update sensor status based on gas levels.

  • Service Layer (services/sensorService.js):

// javascript
export async function updateSensorStatus(sensorId, gasLevel) {
    let status = 'operational';
    if (gasLevel <= 20) status = 'critical';
    else if (gasLevel > 80) status = 'high';

    return await db.sensor.update({
        where: { id: sensorId },
        data: { status },
    });
}

Last updated