import { Injectable, NotFoundException } from '@nestjs/common'; import { PrismaService } from '../prisma/prisma.service'; import { TenantService } from '../tenant/tenant.service'; @Injectable() export class WebsiteFaviconService { constructor( private readonly prisma: PrismaService, private readonly tenant: TenantService, ) {} async getPublic(host: string) { const business = await this.tenant.resolveBusinessByDomain(host); const record = await this.prisma.business.findUnique({ where: { id: business.id }, select: { faviconMediaId: true, logoMedia: { select: { publicUrl: true } }, logoDarkMedia: { select: { publicUrl: true } }, faviconMedia: { select: { publicUrl: true } }, }, }); if (!record) { throw new NotFoundException('Business not found'); } const logoUrl = record.logoMedia?.publicUrl ?? null; const logoDarkUrl = record.logoDarkMedia?.publicUrl ?? null; const faviconUrl = record.faviconMedia?.publicUrl ?? logoUrl; return { faviconUrl, logoUrl, logoDarkUrl, hasDedicatedFavicon: record.faviconMediaId != null, }; } }