channel-cache.service.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { Injectable } from '@nestjs/common';
  2. import { BaseCacheService } from '@box/common/cache/cache-service';
  3. import { tsCacheKeys } from '@box/common/cache/ts-cache-key.provider';
  4. import { ChannelCachePayload } from './channel-cache.builder';
  5. import { RedisService } from '@box/db/redis/redis.service';
  6. @Injectable()
  7. export class ChannelCacheService extends BaseCacheService {
  8. constructor(redis: RedisService) {
  9. super(redis, ChannelCacheService.name);
  10. }
  11. async getAllChannels(): Promise<ChannelCachePayload[]> {
  12. return (
  13. (await this.getJson<ChannelCachePayload[]>(tsCacheKeys.channel.all())) ??
  14. []
  15. );
  16. }
  17. // async getChannelById(id: string): Promise<ChannelCachePayload | null> {
  18. // if (!id) return null;
  19. // return (
  20. // (await this.getJson<ChannelCachePayload>(tsCacheKeys.channel.byId(id))) ??
  21. // null
  22. // );
  23. // }
  24. async getChannelById(channelId: string): Promise<ChannelCachePayload | null> {
  25. if (!channelId) return null;
  26. return (
  27. (await this.getJson<ChannelCachePayload>(
  28. tsCacheKeys.channel.byId(channelId),
  29. )) ?? null
  30. );
  31. }
  32. }