import { Inject, Injectable } from '@nestjs/common'; import { InvalidProfileSlugError, ProfileNotFoundError, } from '../domain/errors.js'; import type { PublicProfile } from '../domain/profile.js'; import type { RelationPlan } from '../domain/relation-plan.js'; import { PROFILE_REPOSITORY, type ProfileRepository, } from './profile.repository.js'; const SLUG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/; @Injectable() export class ProfileService { constructor( @Inject(PROFILE_REPOSITORY) private readonly profiles: ProfileRepository, ) {} async getBySlug(slug: string, plan: RelationPlan): Promise { if (slug.length > 64 || !SLUG.test(slug)) { throw new InvalidProfileSlugError(slug); } const profile = await this.profiles.findBySlug(slug, plan); if (!profile) { throw new ProfileNotFoundError(slug); } return profile; } }