mirror of
https://github.com/immich-app/immich.git
synced 2025-12-28 17:24:56 +03:00
refactor: test utils (#16588)
This commit is contained in:
@@ -15,7 +15,7 @@ export class APIKeyService extends BaseService {
|
||||
throw new BadRequestException('Cannot grant permissions you do not have');
|
||||
}
|
||||
|
||||
const entity = await this.keyRepository.create({
|
||||
const entity = await this.apiKeyRepository.create({
|
||||
key: this.cryptoRepository.hashSha256(secret),
|
||||
name: dto.name || 'API Key',
|
||||
userId: auth.user.id,
|
||||
@@ -26,27 +26,27 @@ export class APIKeyService extends BaseService {
|
||||
}
|
||||
|
||||
async update(auth: AuthDto, id: string, dto: APIKeyUpdateDto): Promise<APIKeyResponseDto> {
|
||||
const exists = await this.keyRepository.getById(auth.user.id, id);
|
||||
const exists = await this.apiKeyRepository.getById(auth.user.id, id);
|
||||
if (!exists) {
|
||||
throw new BadRequestException('API Key not found');
|
||||
}
|
||||
|
||||
const key = await this.keyRepository.update(auth.user.id, id, { name: dto.name });
|
||||
const key = await this.apiKeyRepository.update(auth.user.id, id, { name: dto.name });
|
||||
|
||||
return this.map(key);
|
||||
}
|
||||
|
||||
async delete(auth: AuthDto, id: string): Promise<void> {
|
||||
const exists = await this.keyRepository.getById(auth.user.id, id);
|
||||
const exists = await this.apiKeyRepository.getById(auth.user.id, id);
|
||||
if (!exists) {
|
||||
throw new BadRequestException('API Key not found');
|
||||
}
|
||||
|
||||
await this.keyRepository.delete(auth.user.id, id);
|
||||
await this.apiKeyRepository.delete(auth.user.id, id);
|
||||
}
|
||||
|
||||
async getById(auth: AuthDto, id: string): Promise<APIKeyResponseDto> {
|
||||
const key = await this.keyRepository.getById(auth.user.id, id);
|
||||
const key = await this.apiKeyRepository.getById(auth.user.id, id);
|
||||
if (!key) {
|
||||
throw new BadRequestException('API Key not found');
|
||||
}
|
||||
@@ -54,7 +54,7 @@ export class APIKeyService extends BaseService {
|
||||
}
|
||||
|
||||
async getAll(auth: AuthDto): Promise<APIKeyResponseDto[]> {
|
||||
const keys = await this.keyRepository.getByUserId(auth.user.id);
|
||||
const keys = await this.apiKeyRepository.getByUserId(auth.user.id);
|
||||
return keys.map((key) => this.map(key));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user