refactor(server): use cascades for keys and tokens (#2544)

This commit is contained in:
Jason Rasmussen
2023-05-23 16:40:04 -04:00
committed by GitHub
parent e2bd7e1e08
commit 50a792a81a
19 changed files with 100 additions and 126 deletions
@@ -1,5 +1,10 @@
import { APIKeyEntity } from '@app/infra/entities';
export class APIKeyCreateResponseDto {
secret!: string;
apiKey!: APIKeyResponseDto;
}
export class APIKeyResponseDto {
id!: string;
name!: string;
@@ -6,3 +6,9 @@ export class APIKeyCreateDto {
@IsOptional()
name?: string;
}
export class APIKeyUpdateDto {
@IsString()
@IsNotEmpty()
name!: string;
}
@@ -6,7 +6,6 @@ export interface IKeyRepository {
create(dto: Partial<APIKeyEntity>): Promise<APIKeyEntity>;
update(userId: string, id: string, dto: Partial<APIKeyEntity>): Promise<APIKeyEntity>;
delete(userId: string, id: string): Promise<void>;
deleteAll(userId: string): Promise<void>;
/**
* Includes the hashed `key` for verification
* @param id
@@ -1,10 +1,9 @@
import { BadRequestException, Inject, Injectable } from '@nestjs/common';
import { AuthUserDto } from '../auth';
import { ICryptoRepository } from '../crypto';
import { APIKeyCreateResponseDto, APIKeyResponseDto, mapKey } from './api-key-response.dto';
import { APIKeyCreateDto } from './api-key.dto';
import { IKeyRepository } from './api-key.repository';
import { APIKeyCreateDto } from './dto/api-key-create.dto';
import { APIKeyCreateResponseDto } from './response-dto/api-key-create-response.dto';
import { APIKeyResponseDto, mapKey } from './response-dto/api-key-response.dto';
@Injectable()
export class APIKeyService {
@@ -1,7 +0,0 @@
import { IsNotEmpty, IsString } from 'class-validator';
export class APIKeyUpdateDto {
@IsString()
@IsNotEmpty()
name!: string;
}
@@ -1,2 +0,0 @@
export * from './api-key-create.dto';
export * from './api-key-update.dto';
+2 -2
View File
@@ -1,4 +1,4 @@
export * from './api-key-response.dto';
export * from './api-key.dto';
export * from './api-key.repository';
export * from './api-key.service';
export * from './dto';
export * from './response-dto';
@@ -1,6 +0,0 @@
import { APIKeyResponseDto } from './api-key-response.dto';
export class APIKeyCreateResponseDto {
secret!: string;
apiKey!: APIKeyResponseDto;
}
@@ -1,2 +0,0 @@
export * from './api-key-create-response.dto';
export * from './api-key-response.dto';