feat(scheduling): add notify route and wire up scheduling router
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import { cors } from 'hono/cors';
|
|||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
import vehiclesRouter from './routes/vehicles.js';
|
import vehiclesRouter from './routes/vehicles.js';
|
||||||
import mileageRouter from './routes/mileage/index.js';
|
import mileageRouter from './routes/mileage/index.js';
|
||||||
|
import schedulingRouter from './routes/scheduling/index.js';
|
||||||
import authRouter from './auth/login.js';
|
import authRouter from './auth/login.js';
|
||||||
import { authMiddleware } from './auth/middleware.js';
|
import { authMiddleware } from './auth/middleware.js';
|
||||||
|
|
||||||
@@ -22,6 +23,7 @@ app.use('/api/*', authMiddleware);
|
|||||||
|
|
||||||
app.route('/api/vehicles', vehiclesRouter);
|
app.route('/api/vehicles', vehiclesRouter);
|
||||||
app.route('/api/mileage', mileageRouter);
|
app.route('/api/mileage', mileageRouter);
|
||||||
|
app.route('/api/scheduling', schedulingRouter);
|
||||||
|
|
||||||
app.get('/api/health', (c) => c.json({ status: 'ok', time: new Date().toISOString() }));
|
app.get('/api/health', (c) => c.json({ status: 'ok', time: new Date().toISOString() }));
|
||||||
|
|
||||||
|
|||||||
10
src/server/routes/scheduling/index.ts
Normal file
10
src/server/routes/scheduling/index.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { Hono } from 'hono';
|
||||||
|
import suggestionsRouter from './suggestions.js';
|
||||||
|
import notifyRouter from './notify.js';
|
||||||
|
|
||||||
|
const app = new Hono();
|
||||||
|
|
||||||
|
app.route('/suggestions', suggestionsRouter);
|
||||||
|
app.route('/notify', notifyRouter);
|
||||||
|
|
||||||
|
export default app;
|
||||||
41
src/server/routes/scheduling/notify.ts
Normal file
41
src/server/routes/scheduling/notify.ts
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import { Hono } from 'hono';
|
||||||
|
import type { AuthUser } from '../../auth/types.js';
|
||||||
|
import type { NotifyRequest } from './types.js';
|
||||||
|
|
||||||
|
const app = new Hono();
|
||||||
|
|
||||||
|
// In-memory set of processed suggestion IDs
|
||||||
|
const processedSuggestions = new Set<string>();
|
||||||
|
|
||||||
|
export function isProcessed(suggestionId: string): boolean {
|
||||||
|
return processedSuggestions.has(suggestionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
app.post('/', async (c) => {
|
||||||
|
try {
|
||||||
|
const body = await c.req.json<NotifyRequest>();
|
||||||
|
const { suggestionId, currentPlate, candidatePlate } = body;
|
||||||
|
|
||||||
|
if (!suggestionId || !currentPlate || !candidatePlate) {
|
||||||
|
return c.json({ success: false, message: '缺少必要参数' }, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (processedSuggestions.has(suggestionId)) {
|
||||||
|
return c.json({ success: false, message: '该建议已处理' }, 409);
|
||||||
|
}
|
||||||
|
|
||||||
|
const user = (c as any).get('user') as AuthUser | undefined;
|
||||||
|
const operator = user?.userName || '未知';
|
||||||
|
|
||||||
|
console.log(`[scheduling:notify] operator=${operator} suggestion=${suggestionId} current=${currentPlate} candidate=${candidatePlate}`);
|
||||||
|
|
||||||
|
processedSuggestions.add(suggestionId);
|
||||||
|
|
||||||
|
return c.json({ success: true, message: `替换通知已发送:${currentPlate} → ${candidatePlate}` });
|
||||||
|
} catch (e: unknown) {
|
||||||
|
console.error('scheduling notify error:', e);
|
||||||
|
return c.json({ success: false, message: '发送通知失败' }, 500);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export default app;
|
||||||
Reference in New Issue
Block a user