Przeglądaj źródła

优化二维码服务逻辑,调整非管理员用户的可见性处理,确保在特定条件下仅返回图片 URL。

wuyi 2 tygodni temu
rodzic
commit
24eae8012e
1 zmienionych plików z 9 dodań i 4 usunięć
  1. 9 4
      src/services/qr-code.service.ts

+ 9 - 4
src/services/qr-code.service.ts

@@ -161,10 +161,8 @@ export class QrCodeService {
       info = await this.linkInfoRepository.findOne({ where: { qrCodeId: entity.id } })
     }
 
-    if (!isAdmin && info && info.isVisible === false) {
-      info = null
-      isVisible = false
-    } else if (info) {
+    // 先设置 isVisible 状态
+    if (info) {
       isVisible = info.isVisible ?? true
     }
 
@@ -184,6 +182,13 @@ export class QrCodeService {
       }
     }
 
+    // 如果不是管理员且 isVisible 为 false,只返回图片 URL
+    if (!isAdmin && info && info.isVisible === false) {
+      const photoUrl = 'photoUrl' in info ? info.photoUrl : ''
+      info = { photoUrl }
+      isVisible = false
+    }
+
     const bindRecord = await this.userQrCodeRepository.findOne({
       where: { qrCodeId: entity.id, isDeleted: false }
     })