Просмотр исходного кода

Merge branch 'wudi_dev' of fct/box-nestjs-monorepo into master

wudi 3 недель назад
Родитель
Сommit
fc0015c387

+ 3 - 0
apps/box-app-api/src/feature/auth/auth.service.ts

@@ -24,6 +24,7 @@ type LoginResult = {
   channel: any;
   channel: any;
   startupAds: any | null; // keep as any until you wire your Ad payload DTO
   startupAds: any | null; // keep as any until you wire your Ad payload DTO
   conf: any | null;
   conf: any | null;
+  sysParams: any | null;
 };
 };
 
 
 @Injectable()
 @Injectable()
@@ -108,12 +109,14 @@ export class AuthService {
     // For now return null to keep behaviour deterministic.
     // For now return null to keep behaviour deterministic.
     const startupAds = await this.adService.listAdsByType(1, 20);
     const startupAds = await this.adService.listAdsByType(1, 20);
     const conf = await this.sysParamsService.getSysCnf();
     const conf = await this.sysParamsService.getSysCnf();
+    const sysParams = await this.sysParamsService.getSysParams();
     const channel = await this.channelService.getChannelById(finalChannelId);
     const channel = await this.channelService.getChannelById(finalChannelId);
 
 
     return {
     return {
       uid,
       uid,
       channelId: finalChannelId,
       channelId: finalChannelId,
       channel: channel,
       channel: channel,
+      sysParams,
       startupAds,
       startupAds,
       conf,
       conf,
     };
     };

+ 56 - 1
apps/box-app-api/src/feature/sys-params/sys-params.service.ts

@@ -1,5 +1,6 @@
 import { Injectable } from '@nestjs/common';
 import { Injectable } from '@nestjs/common';
 import { PrismaMongoService } from '../../prisma/prisma-mongo.service';
 import { PrismaMongoService } from '../../prisma/prisma-mongo.service';
+import { RedisService } from '@box/db/redis/redis.service';
 import {
 import {
   AdOrder,
   AdOrder,
   SystemParamSide,
   SystemParamSide,
@@ -17,6 +18,7 @@ export class SysParamsService {
   constructor(
   constructor(
     private readonly prisma: PrismaMongoService,
     private readonly prisma: PrismaMongoService,
     private readonly sysConfigReader: SysConfigReaderService,
     private readonly sysConfigReader: SysConfigReaderService,
+    private readonly redis: RedisService,
   ) {}
   ) {}
 
 
   getHomepageConstants() {
   getHomepageConstants() {
@@ -86,6 +88,59 @@ export class SysParamsService {
   }
   }
 
 
   async getSysCnf() {
   async getSysCnf() {
-    return this.sysConfigReader.getAppConfig();
+   try {
+      // Try to get from Redis cache first
+      const cacheKey = `box:app:sysconf`;
+      const conf = await this.redis.get(cacheKey);
+      if (conf) {
+        return JSON.parse(conf);
+      }
+
+      const appConf = this.sysConfigReader.getAppConfig();
+
+      if (appConf) {
+        // Store in Redis cache for future requests
+        await this.redis.setJson(cacheKey, appConf, 24 * 3600); // Cache for 1 hour
+      }
+
+      return appConf;
+    } catch (error) {
+      return null;
+    }
   }
   }
+
+  async getSysParams() {
+   try {
+      // Try to get from Redis cache first
+      const cacheKey = `box:app:sysparams`;
+      const conf = await this.redis.get(cacheKey);
+      if (conf) {
+        return JSON.parse(conf);
+      }
+
+      const params = await this.prisma.systemParam.findMany({
+        where: {
+          side: SystemParamSide.CLIENT,
+        },
+        orderBy: {
+          id: 'asc', // sequential order by ID
+        },
+      });
+
+      const sysParams = params.map((p, idx) => ({
+        id: p.id.toString(),
+        content: p.value ?? '', // Use 'value' field as content
+        seq: idx,
+      }));
+
+      if (sysParams) {
+        // Store in Redis cache for future requests
+        await this.redis.setJson(cacheKey, sysParams, 24 * 3600); // Cache for 1 hour
+      }
+
+      return sysParams;
+    } catch (error) {
+      return null;
+    }
+  }  
 }
 }