Browse Source

🐞 fix: 修复了若干bug

Pchen. 8 months ago
parent
commit
b6031b98b0

+ 3 - 2
apis/ClockIn/AddAttendanceItems.js

@@ -57,10 +57,11 @@ class AddAttendanceItems extends API {
         user = user.split('|');
         admin = admin.split('|');
 
-        let uuids, admins;
+        let uuids = [], admins = [];
         try {
             uuids = await AccessControl.checkUser(user);
-            admins = await AccessControl.checkUser(admin);
+            if(admin != '')
+                admins = await AccessControl.checkUser(admin);
         } catch (error) {
             return res.json({
                 ...BaseStdResponse.ERR,

+ 6 - 12
apis/ClockIn/GetAttendanceItemDetail.js

@@ -51,18 +51,12 @@ class GetAttendanceItemDetail extends API {
             const userUuids = new Set();
             const addUserUuid = (uuid) => userUuids.add(uuid);
 
-            for (let item of projectResult) {
-                addUserUuid(item.uuid);
-                const users = JSON.parse(item.user || '[]');
-                users.forEach(addUserUuid);
-
-                if (item.admin) {
-                    const admins = JSON.parse(item.admin);
-                    admins.forEach(addUserUuid);
-                }
-
+            projectResult.forEach(item => {
                 addUserUuid(item.createUser);
-            }
+                item.user.forEach(addUserUuid);
+                item.admin.forEach(addUserUuid);
+                addUserUuid(item.createUser);
+            });
 
             // 如果没有需要查询的用户,直接返回结果
             if (userUuids.size === 0) {
@@ -80,7 +74,7 @@ class GetAttendanceItemDetail extends API {
             await Promise.all(Array.from(userUuids).map(async (uuid) => {
                 const userCache = await UserInfoCache.getUserByUuid(uuid);
                 userInfo[uuid] = {
-                    userCache
+                    ...userCache
                 };
             }));
 

+ 7 - 10
apis/ClockIn/GetAttendanceItemList.js

@@ -50,7 +50,7 @@ class GetAttendanceItemList extends API {
             if (!items) {
                 return res.json({
                     ...BaseStdResponse.DATABASE_ERR,
-                    endpoint: 154754511
+                    endpoint: 1547544
                 });
             }
 
@@ -59,13 +59,9 @@ class GetAttendanceItemList extends API {
             const addUserUuid = (uuid) => userUuids.add(uuid);
 
             items.forEach(item => {
-                addUserUuid(item.uuid);
-                const users = JSON.parse(item.user || '[]');
-                users.forEach(addUserUuid);
-                if (item.admin) {
-                    const admins = JSON.parse(item.admin);
-                    admins.forEach(addUserUuid);
-                }
+                addUserUuid(item.createUser);
+                item.user.forEach(addUserUuid);
+                item.admin.forEach(addUserUuid);
                 addUserUuid(item.createUser);
             });
 
@@ -84,7 +80,7 @@ class GetAttendanceItemList extends API {
             await Promise.all(Array.from(userUuids).map(async (uuid) => {
                 const userCache = await UserInfoCache.getUserByUuid(uuid);
                 userInfo[uuid] = {
-                    userCache
+                    ...userCache
                 };
 
             }));
@@ -95,9 +91,10 @@ class GetAttendanceItemList extends API {
                 userInfo
             });
         } catch (error) {
+            this.logger.error(`获取考勤列表时出错:${error.stack}`);
             res.json({
                 ...BaseStdResponse.DATABASE_ERR,
-                endpoint: 154754511
+                endpoint: 154754511,
             });
         }
     }

+ 5 - 7
apis/ClockIn/GetMyAttendanceItems.js

@@ -31,20 +31,18 @@ class GetMyAttendanceItems extends API {
         }
 
         try {
-            const conn = db.getConnection();
-
             // 查询用户考勤项目
             const sqlGetItems = `
                 SELECT id, name, user, day_of_week, loopy, begintime, endtime, address
                 FROM kq_items
                 WHERE JSON_CONTAINS(user, JSON_QUOTE(?), '$') ORDER BY id DESC
             `;
-            const items = await conn.query(sqlGetItems, [uuid]);
+            const items = await db.query(sqlGetItems, [uuid]);
 
             if (!items) {
                 return res.json({
                     ...BaseStdResponse.DATABASE_ERR,
-                    endpoint: 154754511
+                    endpoint: 154766
                 });
             }
 
@@ -54,12 +52,12 @@ class GetMyAttendanceItems extends API {
                 FROM kq_records
                 WHERE uuid = ?
             `;
-            const records = await conn.query(sqlGetRecords, [uuid]);
+            const records = await db.query(sqlGetRecords, [uuid]);
 
             if (records === undefined) {
                 return res.json({
                     ...BaseStdResponse.DATABASE_ERR,
-                    endpoint: 154754511
+                    endpoint: 154756
                 });
             }
 
@@ -71,7 +69,7 @@ class GetMyAttendanceItems extends API {
         } catch (error) {
             res.json({
                 ...BaseStdResponse.DATABASE_ERR,
-                endpoint: 154754511
+                endpoint: 154754
             });
         }
     }

+ 1 - 1
apis/ClockIn/SupplementRecord.js

@@ -63,7 +63,7 @@ class SupplementRecord extends API {
             const sqlGetUserUUID = `
                 SELECT uuid
                 FROM users
-                WHERE name = ?
+                WHERE username = ?
             `;
             const userUUIDData = await db.query(sqlGetUserUUID, [user]);
 

+ 1 - 1
lib/AccessControl.js

@@ -25,7 +25,7 @@ class AccessControl {
             let uuids = [];
 
             let queries = maintainers.map(async (maintainer) => {
-                const sql = 'SELECT uuid FROM `users_permission` WHERE name = ?';
+                const sql = 'SELECT uuid FROM `users` WHERE username = ?';
                 const rows = await db.query(sql, [maintainer]);
 
                 if (!rows || rows.length === 0) {

+ 1 - 1
plugin/DataBase/MySQL.js

@@ -32,7 +32,7 @@ class MySQL {
             const [rows] = await this.connection.execute(sql, params);
             return rows;
         } catch (error) {
-            this.logger.error('执行SQL语句时出错:', error);
+            this.logger.error(`执行SQL语句时出错:${error.stack}`);
             throw error;
         }
     }