From 3cc9767dcb9fe1a552399d7e6fae9612bba7e1f8 Mon Sep 17 00:00:00 2001 From: zhangyiming Date: Tue, 1 Dec 2020 17:11:41 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=AE=A1=E7=90=86=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=8E=A5=E5=8F=A3=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/router/api/mysql.ts | 36 +++++++++++++++++++++++++-------- backend/src/server.ts | 2 +- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/backend/src/router/api/mysql.ts b/backend/src/router/api/mysql.ts index f2710bf7f..5e72c900d 100644 --- a/backend/src/router/api/mysql.ts +++ b/backend/src/router/api/mysql.ts @@ -32,7 +32,6 @@ let generateVerify: number */ /** - * 登录 * @route POST /login * @param {Login.model} point.body.required - the new point * @produces application/json application/xml @@ -87,7 +86,6 @@ const login = async (req: Request, res: Response) => { */ /** -* 注册 * @route POST /register * @param {Register.model} point.body.required - the new point * @produces application/json application/xml @@ -150,16 +148,41 @@ const updateList = async (req: Request, res: Response) => { } /** - * 列表删除 - * @route GET /deleteList + * @typedef DeleteList + * @property {integer} id.required - 当前id + */ + +/** + * @route DELETE /deleteList/{id} * @summary 列表删除 + * @param {DeleteList.model} id.path.required - 用户id * @group 用户管理相关 * @returns {object} 200 + * @returns {Array.} DeleteList * @security JWT */ const deleteList = async (req: Request, res: Response) => { - res.json({ code: 1, msg: "成功" }) + const { id } = req.params + let payload = null + try { + const authorizationHeader = req.get("Authorization") + const accessToken = authorizationHeader.substr("Bearer ".length) + payload = jwt.verify(accessToken, secret.jwtSecret) + } catch (error) { + return res.status(401).end() + } + var sql = 'DELETE FROM users where id=' + "'" + id + "'" + connection.query(sql, async function (err, data) { + if (err) { + console.log(err) + } else { + await res.json({ + code: 0, + info: '删除成功' + }) + } + }) } /** @@ -169,7 +192,6 @@ const deleteList = async (req: Request, res: Response) => { */ /** -* 分页查询 * @route POST /searchPage * @param {SearchPage.model} point.body.required - the new point * @produces application/json application/xml @@ -212,7 +234,6 @@ const searchPage = async (req: Request, res: Response) => { */ /** -* 模糊查询(根据用户名) * @route POST /searchVague * @param {SearchVague.model} point.body.required - the new point * @produces application/json application/xml @@ -257,7 +278,6 @@ const searchVague = async (req: Request, res: Response) => { } /** - * 图形验证码 * @route GET /captcha * @summary 图形验证码 * @group captcha - 图形验证码 diff --git a/backend/src/server.ts b/backend/src/server.ts index 8cf56949f..85facfc50 100644 --- a/backend/src/server.ts +++ b/backend/src/server.ts @@ -31,7 +31,7 @@ app.get('/updateList', (req, res) => { updateList(req, res) }) -app.get('/deleteList', (req, res) => { +app.delete('/deleteList/:id', (req, res) => { deleteList(req, res) })