60 lines
No EOL
1.7 KiB
TypeScript
60 lines
No EOL
1.7 KiB
TypeScript
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 });
|
|
}
|
|
} |