Explorar el Código

feat: add isDefault field to Channel model and update channel creation logic

Dave hace 1 mes
padre
commit
bb0027cd65

+ 3 - 0
apps/box-mgnt-api/src/mgnt-backend/feature/channel/channel.service.ts

@@ -64,6 +64,8 @@ export class ChannelService {
       );
     }
 
+    const isDefault = (await this.mongoPrismaService.channel.count()) === 0;
+
     const now = this.now();
 
     const channel = await this.mongoPrismaService.channel.create({
@@ -76,6 +78,7 @@ export class ChannelService {
         clientName: this.trimOptional(dto.clientName) ?? null,
         clientNotice: this.trimOptional(dto.clientNotice) ?? null,
         remark: this.trimOptional(dto.remark) ?? null,
+        isDefault,
         categories: (dto.categories as any) || null,
         tags: (dto.tags as any) || null,
         tagNames: dto.tagNames || [],

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

@@ -8,6 +8,7 @@ model Channel {
   clientName    String?                         // 客户端名称
   clientNotice  String?                         // 客户端公告
   remark        String?                         // 备注
+  isDefault     Boolean   @default(false)       // 默认渠道
 
   // epoch (recommended: ms) stored as BigInt
   createAt      BigInt     @default(0)          // 创建时间