routes.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import express from 'express';
  2. const router = express.Router();
  3. // GET /api/finance — 财务记录列表
  4. router.get('/', async (req, res) => {
  5. try {
  6. const Parse = (globalThis as any).Parse;
  7. const q = new Parse.Query('FinanceRecord');
  8. q.descending('orderDate');
  9. q.limit(100);
  10. const { status } = req.query;
  11. if (status && status !== 'all') {
  12. q.equalTo('status', status);
  13. }
  14. const list = await q.find({ useMasterKey: true });
  15. const data = list.map((r: any) => r.toJSON());
  16. res.json({ success: true, data });
  17. } catch (e: any) {
  18. res.status(500).json({ success: false, error: e.message });
  19. }
  20. });
  21. // POST /api/finance/verify — 核销确认
  22. router.post('/verify', async (req, res) => {
  23. try {
  24. const Parse = (globalThis as any).Parse;
  25. const { id } = req.body;
  26. if (!id) {
  27. return res.status(400).json({ success: false, error: '缺少 id' });
  28. }
  29. const q = new Parse.Query('FinanceRecord');
  30. const record = await q.get(id, { useMasterKey: true });
  31. record.set('verified', true);
  32. const saved = await record.save(null, { useMasterKey: true });
  33. res.json({ success: true, data: saved.toJSON() });
  34. } catch (e: any) {
  35. res.status(500).json({ success: false, error: e.message });
  36. }
  37. });
  38. export default router;