| 123456789101112131415161718192021222324252627282930 |
- import { Logger } from '@nestjs/common';
- import { RedisService } from '@box/db/redis/redis.service';
- import { MongoPrismaService } from '@box/db/prisma/mongo-prisma.service';
- /**
- * Base class for cache builders that read from MongoDB and publish JSON into Redis.
- */
- export abstract class BaseCacheBuilder {
- protected readonly logger: Logger;
- protected constructor(
- protected readonly redis: RedisService,
- protected readonly mongoPrisma: MongoPrismaService,
- loggerContext?: string,
- ) {
- this.logger = new Logger(loggerContext ?? new.target.name);
- }
- /** Build every cache item managed by this builder. */
- abstract buildAll(): Promise<void>;
- /**
- * Convert Prisma BigInt timestamps to numbers for JSON payloads.
- * Falls back to the original number when already numeric.
- */
- protected toMillis(value?: bigint | number | null): number | null {
- if (value === null || value === undefined) return null;
- return typeof value === 'bigint' ? Number(value) : value;
- }
- }
|