Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | import Router from '@koa/router'; import { feedbackService, FeedbackInput } from './feedback.service'; const router = new Router(); /** * 提交反馈 * POST /api/feedback */ router.post('/', async (ctx) => { try { const { type, title, content, contact, screenshotUrls } = ctx.request.body as FeedbackInput; // 参数验证 if (!type || !['suggestion', 'bug', 'other'].includes(type)) { ctx.status = 400; ctx.body = { code: 400, message: 'type must be one of: suggestion, bug, other' }; return; } if (!title || typeof title !== 'string' || title.trim().length === 0) { ctx.status = 400; ctx.body = { code: 400, message: 'title is required' }; return; } if (!content || typeof content !== 'string' || content.trim().length === 0) { ctx.status = 400; ctx.body = { code: 400, message: 'content is required' }; return; } const result = await feedbackService.submitFeedback({ type, title: title.trim(), content: content.trim(), contact: contact?.trim(), screenshotUrls, }); ctx.body = { code: 0, message: 'success', data: result, }; } catch (error: any) { ctx.status = 500; ctx.body = { code: 500, message: error.message || '提交反馈失败', }; } }); export default router; |