it_solutions_test/src/profile/application/profile.service.ts
Илья Братских bd22447bd3 Add a GraphQL digital card that migrates and seeds itself on startup.
The NestJS API serves the public profile through Apollo Sandbox and loads only the relations selected by the query.
2026-11-02 05:30:54 +03:00

34 lines
888 B
TypeScript

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<PublicProfile> {
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;
}
}