widgetdc-cortex / apps /backend /src /routes /neo4j-sync.ts
Kraft102's picture
Deploy from GitHub Actions 2025-12-15_23-41-14
bbf18eb verified
/**
* Neo4j Sync API Routes
*
* Provides REST endpoints for Neo4j sync status and control.
*/
import { Router, Request, Response } from 'express';
import { getNeo4jAutoSync } from '../services/Neo4jAutoSync.js';
const router = Router();
/**
* GET /api/neo4j-sync/status
* Get current sync status
*/
router.get('/status', (_req: Request, res: Response) => {
try {
const syncService = getNeo4jAutoSync();
const status = syncService.getStatus();
res.json({
success: true,
data: status
});
} catch (error: any) {
res.status(500).json({
success: false,
error: error.message
});
}
});
/**
* POST /api/neo4j-sync/sync
* Trigger a sync (incremental by default)
*/
router.post('/sync', async (req: Request, res: Response) => {
try {
const { full = false } = req.body || {};
const syncService = getNeo4jAutoSync();
// Return immediately, sync runs in background
res.json({
success: true,
message: `${full ? 'Full' : 'Incremental'} sync started`,
data: { type: full ? 'full' : 'incremental' }
});
// Run sync in background
syncService.sync(full).catch(err => {
console.error('Background sync failed:', err);
});
} catch (error: any) {
res.status(500).json({
success: false,
error: error.message
});
}
});
/**
* POST /api/neo4j-sync/scheduler/start
* Start the scheduler
*/
router.post('/scheduler/start', (_req: Request, res: Response) => {
try {
const syncService = getNeo4jAutoSync();
syncService.startScheduler();
res.json({
success: true,
message: 'Scheduler started',
data: syncService.getStatus()
});
} catch (error: any) {
res.status(500).json({
success: false,
error: error.message
});
}
});
/**
* POST /api/neo4j-sync/scheduler/stop
* Stop the scheduler
*/
router.post('/scheduler/stop', (_req: Request, res: Response) => {
try {
const syncService = getNeo4jAutoSync();
syncService.stopScheduler();
res.json({
success: true,
message: 'Scheduler stopped'
});
} catch (error: any) {
res.status(500).json({
success: false,
error: error.message
});
}
});
export default router;