Forráskód Böngészése

refactor: update channel resolution to match by name and enforce uniqueness on channel name

Dave 1 hónapja
szülő
commit
120d4d55c2

+ 11 - 7
apps/box-app-api/src/feature/auth/auth.service.ts

@@ -179,17 +179,13 @@ export class AuthService {
     });
   }
 
-  // ---------------------------
-  // Channel resolution (box-admin)
-  // ---------------------------
-
   private async resolveFirstLoginChannel(
     channelIdInput?: string,
   ): Promise<any> {
-    // 1) If client provided channelId, validate it exists
+    // 1) If client provided channelId, match channel by name, validate it exists
     if (channelIdInput) {
-      const byId = await this.getChannelByChannelId(channelIdInput);
-      if (byId) return byId;
+      const byName = await this.getChannelByChannelName(channelIdInput);
+      if (byName) return byName;
     }
 
     // 2) Use default channel where isDefault=true
@@ -206,6 +202,14 @@ export class AuthService {
     );
   }
 
+  private async getChannelByChannelName(
+    channelName: string,
+  ): Promise<any | null> {
+    return this.prismaMongoService.channel.findUnique({
+      where: { name: channelName },
+    });
+  }
+
   private async getChannelByChannelId(channelId: string): Promise<any | null> {
     return this.prismaMongoService.channel.findUnique({
       where: { channelId },

+ 1 - 1
prisma/mongo/schema/channel.prisma

@@ -3,7 +3,7 @@ model Channel {
   channelId    String   @unique
   channelNo    Int?     @unique
 
-  name         String                             // 渠道名称
+  name         String   @unique                   // 渠道名称
   landingUrl   String                             // 最新网址
   videoCdn     String?                            // 视频CDN
   coverCdn     String?                            // 封面CDN