first commit

This commit is contained in:
yanpeng200212
2026-10-08 10:43:59 +08:00
commit 8430ba0452
288 changed files with 29595 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
import { Router } from 'express';
import db from '../db.js';
import { auth } from '../middleware.js';
const router = Router();
// 物业通知列表
router.get('/', (req, res) => {
const notices = db.prepare('SELECT * FROM notices ORDER BY created_at DESC').all();
res.json(notices);
});
// 发布通知(管理员)
router.post('/', auth, (req, res) => {
if (req.user.role !== 'admin') {
return res.status(403).json({ message: '仅管理员可发布通知' });
}
const { title, content, type } = req.body;
if (!title || !content) {
return res.status(400).json({ message: '请填写标题和内容' });
}
const info = db
.prepare('INSERT INTO notices (title, content, type) VALUES (?, ?, ?)')
.run(title, content, type || '通知');
res.json(db.prepare('SELECT * FROM notices WHERE id = ?').get(info.lastInsertRowid));
});
export default router;