import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import { ApiKey } from '../../domain/entities/api-key.entity'; @Injectable() export class ApiKeyRepository { constructor( @InjectRepository(ApiKey) private readonly repo: Repository, ) {} async findByKeyHash(keyHash: string): Promise { return this.repo.findOneBy({ keyHash }); } async findByUserId(userId: string): Promise { return this.repo.find({ where: { userId } }); } async save(apiKey: ApiKey): Promise { return this.repo.save(apiKey); } }