Browse Source

✨ feat: 修改下一路径的获取方式

Pchen. 9 months ago
parent
commit
c9c84146f9
2 changed files with 20 additions and 71 deletions
  1. 20 2
      apis/Lepao/Path/ChangePathState.js
  2. 0 69
      apis/Lepao/Path/GetNextPath.js

+ 20 - 2
apis/Lepao/Path/ChangePathState.js

@@ -42,11 +42,29 @@ class ChangePathState extends API {
             let r = await db.query(sql, [state, id])
             let r = await db.query(sql, [state, id])
 
 
             if (r && r.affectedRows > 0) {
             if (r && r.affectedRows > 0) {
+                let sql = `
+                        SELECT
+                            id
+                        FROM
+                            path_data
+                        WHERE id > ?
+                        LIMIT 1
+                    `
+                let rows = await db.query(sql, [id])
+
+                if (!rows || rows.length === 0)
+                    return res.json({
+                        ...BaseStdResponse.OK,
+                        msg: '审核完毕!无未审核路径'
+                    })
+
                 res.json({
                 res.json({
-                    ...BaseStdResponse.OK
+                    ...BaseStdResponse.OK,
+                    data: rows[0].id,
+                    msg: '切换成功!正在转到下一未审核路径'
                 })
                 })
             } else {
             } else {
-                res.json({ ...BaseStdResponse.ERR,  msg: '改变路径状态失败!数据库错误' })
+                res.json({ ...BaseStdResponse.ERR, msg: '改变路径状态失败!数据库错误' })
             }
             }
         } catch (err) {
         } catch (err) {
             this.logger.error(`改变路径状态失败!${err.stack}`)
             this.logger.error(`改变路径状态失败!${err.stack}`)

+ 0 - 69
apis/Lepao/Path/GetNextPath.js

@@ -1,69 +0,0 @@
-const API = require("../../../lib/API")
-const db = require("../../../plugin/DataBase/db")
-const AccessControl = require("../../../lib/AccessControl")
-const { BaseStdResponse } = require("../../../BaseStdResponse")
-
-class GetNextPath extends API {
-    constructor() {
-        super();
-
-        this.setPath('/Lepao/GetNextPath')
-        this.setMethod('GET')
-    }
-
-    async onRequest(req, res) {
-        let {
-            uuid,
-            session,
-            id
-        } = req.query
-
-        if ([uuid, session, id].some(value => value === '' || value === null || value === undefined))
-            return res.json({
-                ...BaseStdResponse.MISSING_PARAMETER
-            })
-
-        // 检查 session
-        if (!await AccessControl.checkSession(uuid, session))
-            return res.status(401).json({
-                ...BaseStdResponse.ACCESS_DENIED
-            })
-
-        // 检查权限
-        let permission = await AccessControl.getPermission(uuid)
-        if (!permission.includes("admin") && !permission.includes("path"))
-            return res.json({
-                ...BaseStdResponse.PERMISSION_DENIED
-            })
-
-        let sql = `
-            SELECT
-                id
-            FROM
-                path_data
-            WHERE id > ?
-            LIMIT 1
-        `
-
-        let rows = await db.query(sql, [id])
-
-        if (!rows)
-            return res.json({
-                ...BaseStdResponse.MISSING_FILE,
-                msg: '获取路径数据失败!'
-            })
-
-        if(rows.length === 0) 
-           return res.json({
-                ...BaseStdResponse.MISSING_FILE,
-                msg: '无未审核路径!'
-            }) 
-
-        res.json({
-            ...BaseStdResponse.OK,
-            data
-        })
-    }
-}
-
-module.exports.GetNextPath = GetNextPath