fusero-app-boilerplate/src/apps/_app/services/APIKeyService.ts
2025-04-29 07:51:17 +02:00

19 lines
609 B
TypeScript

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<string | null> {
const apiKey = await this.apiKeyRepository.findAPIKeyByUserId(userId);
return apiKey ? apiKey.key : null;
}
}