warning system
This commit is contained in:
parent
5e029ff99c
commit
0c5c7bcb5f
10 changed files with 1074 additions and 54 deletions
60
app/api/sensors/zones/route.ts
Normal file
60
app/api/sensors/zones/route.ts
Normal file
|
@ -0,0 +1,60 @@
|
|||
import { NextResponse } from 'next/server';
|
||||
import { ZONE_CONFIGS, validateSensorConfig } from '@/utils/sensorConfig';
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
zones: ZONE_CONFIGS,
|
||||
description: 'Available sensor zones with default threshold configurations',
|
||||
timestamp: new Date().toISOString()
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Zone config API error:', error);
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: 'Failed to get zone configurations',
|
||||
zones: {},
|
||||
timestamp: new Date().toISOString()
|
||||
}, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const sensorConfigs = await request.json();
|
||||
|
||||
if (!Array.isArray(sensorConfigs)) {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: 'Expected array of sensor configurations'
|
||||
}, { status: 400 });
|
||||
}
|
||||
|
||||
const validationResults = sensorConfigs.map(config => ({
|
||||
sensorId: config.id,
|
||||
...validateSensorConfig(config)
|
||||
}));
|
||||
|
||||
const hasErrors = validationResults.some(result => !result.isValid);
|
||||
|
||||
return NextResponse.json({
|
||||
success: !hasErrors,
|
||||
validationResults,
|
||||
summary: {
|
||||
total: sensorConfigs.length,
|
||||
valid: validationResults.filter(r => r.isValid).length,
|
||||
withWarnings: validationResults.filter(r => r.warnings.length > 0).length,
|
||||
withErrors: validationResults.filter(r => !r.isValid).length
|
||||
},
|
||||
timestamp: new Date().toISOString()
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('Sensor validation API error:', error);
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: 'Failed to validate sensor configurations'
|
||||
}, { status: 500 });
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue