浏览代码

feat: add adId field to AdPoolEntry and update related services for consistency

Dave 1 月之前
父节点
当前提交
f14273988c

+ 1 - 0
libs/common/src/ads/ad-types.ts

@@ -45,6 +45,7 @@ export interface AdPoolPlacement {
  */
 export interface AdPoolEntry {
   id: string; // Ads.id (Mongo ObjectId string)
+  adId: number; // Ads.adId (numeric ID)
   adType: AdType;
   advertiser: string;
   title: string;

+ 5 - 0
libs/core/src/ad/ad-cache-warmup.service.ts

@@ -8,6 +8,7 @@ import { nowSecBigInt } from '@box/common/time/time.util';
 
 interface CachedAd {
   id: string;
+  adId: number;
   adType: string;
   advertiser: string;
   title: string;
@@ -69,6 +70,7 @@ export class AdCacheWarmupService implements OnModuleInit {
         orderBy: { seq: 'asc' },
         select: {
           id: true,
+          adId: true,
           adType: true,
           advertiser: true,
           title: true,
@@ -92,6 +94,7 @@ export class AdCacheWarmupService implements OnModuleInit {
         try {
           await this.cacheAd(ad.id, {
             id: ad.id,
+            adId: ad.adId,
             adType: ad.adType,
             advertiser: ad.advertiser,
             title: ad.title,
@@ -143,6 +146,7 @@ export class AdCacheWarmupService implements OnModuleInit {
       where: { id: adId },
       select: {
         id: true,
+        adId: true,
         adType: true,
         advertiser: true,
         title: true,
@@ -182,6 +186,7 @@ export class AdCacheWarmupService implements OnModuleInit {
     // Cache the ad
     await this.cacheAd(adId, {
       id: ad.id,
+      adId: ad.adId,
       adType: ad.adType,
       advertiser: ad.advertiser,
       title: ad.title,

+ 4 - 0
libs/core/src/ad/ad-pool.service.ts

@@ -64,6 +64,7 @@ export class AdPoolService {
       orderBy: { seq: 'asc' },
       select: {
         id: true,
+        adId: true,
         adType: true,
         advertiser: true,
         title: true,
@@ -83,6 +84,7 @@ export class AdPoolService {
 
     const payloads: AdPayload[] = ads.map((ad) => ({
       id: ad.id,
+      adId: ad.adId,
       adType: ad.adType as AdType,
       advertiser: ad.advertiser,
       title: ad.title,
@@ -144,6 +146,7 @@ export class AdPoolService {
         },
         select: {
           id: true,
+          adId: true,
           adType: true,
           advertiser: true,
           title: true,
@@ -168,6 +171,7 @@ export class AdPoolService {
 
       const payload: AdPayload = {
         id: ad.id,
+        adId: ad.adId,
         adType: ad.adType,
         advertiser: ad.advertiser,
         title: ad.title,

+ 6 - 4
libs/core/src/cache/category/category-cache.service.ts

@@ -12,16 +12,18 @@ export class CategoryCacheService extends BaseCacheService {
 
   async getAllCategories(): Promise<CategoryCachePayload[]> {
     return (
-      (await this.getJson<CategoryCachePayload[]>(tsCacheKeys.category.all())) ??
-      []
+      (await this.getJson<CategoryCachePayload[]>(
+        tsCacheKeys.category.all(),
+      )) ?? []
     );
   }
 
   async getCategoryById(id: string): Promise<CategoryCachePayload | null> {
     if (!id) return null;
     return (
-      (await this.getJson<CategoryCachePayload>(tsCacheKeys.category.general(id))) ??
-      null
+      (await this.getJson<CategoryCachePayload>(
+        tsCacheKeys.category.general(id),
+      )) ?? null
     );
   }
 }

+ 2 - 0
libs/core/src/cache/channel/channel-cache.builder.ts

@@ -6,6 +6,7 @@ import { MongoPrismaService } from '@box/db/prisma/mongo-prisma.service';
 
 export interface ChannelCachePayload {
   id: string;
+  channelId: string;
   name: string;
   landingUrl: string;
   videoCdn?: string;
@@ -28,6 +29,7 @@ export class ChannelCacheBuilder extends BaseCacheBuilder {
 
     const payloads: ChannelCachePayload[] = channels.map((channel) => ({
       id: channel.id,
+      channelId: channel.channelId,
       name: channel.name,
       landingUrl: channel.landingUrl,
       videoCdn: channel.videoCdn ?? undefined,

+ 2 - 1
libs/core/src/cache/channel/channel-cache.service.ts

@@ -12,7 +12,8 @@ export class ChannelCacheService extends BaseCacheService {
 
   async getAllChannels(): Promise<ChannelCachePayload[]> {
     return (
-      (await this.getJson<ChannelCachePayload[]>(tsCacheKeys.channel.all())) ?? []
+      (await this.getJson<ChannelCachePayload[]>(tsCacheKeys.channel.all())) ??
+      []
     );
   }
 

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

@@ -1,6 +1,6 @@
 model Ads {
   id           String     @id @map("_id") @default(auto()) @db.ObjectId
-  adId         Int        @unique
+  adId         Int?        @unique
   adType       AdType     // Redis key & module type
   advertiser   String     // 广告商 (业务上限制 max 20 字符)
   title        String     // 标题 (业务上限制 max 20 字符)