19 lines
609 B
TypeScript
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;
|
|
}
|
|
}
|