- Fixed foreign key constraint violation in automation service - Added user upsert to ensure user exists before creating automation session - Enhanced error reporting in automation start API - Added comprehensive AI learning system documentation - Automation now starts successfully in simulation mode
31 lines
929 B
JavaScript
31 lines
929 B
JavaScript
import { NextResponse } from 'next/server'
|
|
import { automationService } from '@/lib/automation-service-simple'
|
|
|
|
export async function POST(request) {
|
|
try {
|
|
const config = await request.json()
|
|
|
|
// Add a default userId for now (in production, get from auth)
|
|
const automationConfig = {
|
|
userId: 'default-user',
|
|
...config
|
|
}
|
|
|
|
const success = await automationService.startAutomation(automationConfig)
|
|
|
|
if (success) {
|
|
return NextResponse.json({ success: true, message: 'Automation started successfully' })
|
|
} else {
|
|
return NextResponse.json({ success: false, error: 'Failed to start automation' }, { status: 500 })
|
|
}
|
|
} catch (error) {
|
|
console.error('Start automation error:', error)
|
|
return NextResponse.json({
|
|
success: false,
|
|
error: 'Internal server error',
|
|
message: error.message,
|
|
stack: error.stack
|
|
}, { status: 500 })
|
|
}
|
|
}
|