import { EntityManager } from '@mikro-orm/core'; import { APIKeyRepository } from '../repositories/APIKeyRepository'; import { APIKey } from '../entities/apikey/_APIKey'; export class APIKeyService { private apiKeyRepository: APIKeyRepository; private em: EntityManager; constructor(em: EntityManager) { this.em = em; this.apiKeyRepository = this.em.getRepository(APIKey); } async getAPIKeyForUser(userId: number): Promise { const apiKey = await this.apiKeyRepository.findAPIKeyByUserId(userId); return apiKey ? apiKey.key : null; } }