(编辑器区域 · 仅原型展示)
38import { Request, Response } from 'express';
39
40export async function getUser(req: Request, res: Response) {
41 const userId = req.params.id;
42 const result = await db.query(`SELECT * FROM users WHERE id = ${userId}`);
Code Review (1 / 5) — src/api.ts:L42
[未处理]
SQL 查询通过字符串拼接构造,存在注入风险。请使用参数化查询。
43 if (!result.rows.length) {
44 return res.status(404).json({ error: 'Not found' });
45 }
46 return res.json(result.rows[0]);
47}
48
49// TODO: add input validation
50export async function updateUser(req: Request, res: Response) {