Inputs models refactor

This commit is contained in:
Gabriel Rosa
2022-09-06 11:45:12 -03:00
parent 469f165cba
commit 2c8ed40bc6
6 changed files with 104 additions and 123 deletions
+66 -93
View File
@@ -1,29 +1,7 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { ApiProperty, ApiPropertyOptional, OmitType } from '@nestjs/swagger';
import { Info } from 'protospack/dist/lib/interfaces';
export class InputModel {
category: string;
plugin: string;
name: string;
cron?: string;
credentials?: {
connection_type: string;
oauth: string;
oauth_code: string;
start_date: string;
};
}
export class FileFormatParams {
@ApiProperty()
sep: string;
@ApiProperty()
header: boolean;
@ApiProperty()
encoding: string;
}
class GoogleAnalyticsClientSecrets {
export class GoogleAnalyticsClientSecrets {
@ApiProperty()
type: string;
@ApiProperty()
@@ -45,7 +23,7 @@ class GoogleAnalyticsClientSecrets {
@ApiProperty()
client_x509_cert_url: string;
}
class OauthObject {
export class OauthObject {
@ApiPropertyOptional()
get_tokens_url: string;
@ApiPropertyOptional()
@@ -55,7 +33,7 @@ class OauthObject {
@ApiPropertyOptional()
content_type: string;
}
class InputOptions {
export class InputOptions {
@ApiPropertyOptional()
oauth: OauthObject;
@ApiPropertyOptional()
@@ -65,8 +43,22 @@ class InputOptions {
@ApiPropertyOptional()
skip_transformation: true;
}
export class FileFormatParams {
@ApiProperty()
sep: string;
@ApiProperty()
header: boolean;
@ApiProperty()
encoding: string;
}
class CredentialsJdbc {
export class AuthParameters {
@ApiProperty()
aws_access_key_id: string;
@ApiProperty()
aws_secret_access_key: string;
}
export class CredentialsJdbc {
@ApiPropertyOptional()
jdbc_user: string;
@ApiPropertyOptional()
@@ -82,8 +74,7 @@ class CredentialsJdbc {
@ApiPropertyOptional()
schema: string;
}
class Credentials extends CredentialsJdbc {
export class Credentials extends CredentialsJdbc {
@ApiProperty()
connection_type: string;
@@ -110,13 +101,13 @@ class Credentials extends CredentialsJdbc {
@ApiPropertyOptional()
oauth_code: string;
}
class Column {
export class Column {
@ApiProperty()
name: string;
@ApiProperty()
type: string;
}
class TableColumns {
export class TableColumns {
@ApiProperty()
name: string;
@ApiProperty()
@@ -124,6 +115,45 @@ class TableColumns {
@ApiProperty()
references: Column[];
}
export class Input {
@ApiProperty()
id: string;
@ApiProperty({ type: [TableColumns] })
tables: TableColumns[];
@ApiProperty()
name: string;
@ApiProperty()
description: string;
@ApiProperty()
plugin: string;
@ApiPropertyOptional()
type?: string;
@ApiProperty()
created_at: string;
@ApiProperty()
updated_at: string;
//deprecated attributes (for retro compatibility)
@ApiPropertyOptional({ deprecated: true })
category: string;
@ApiPropertyOptional({ deprecated: true })
credentials: Credentials;
@ApiPropertyOptional({ deprecated: true })
options: InputOptions;
@ApiPropertyOptional({ deprecated: true })
info: Info;
@ApiPropertyOptional({ deprecated: true })
cron: string;
@ApiPropertyOptional({ deprecated: true })
source_bucket: string;
@ApiPropertyOptional({ deprecated: true })
source_prefix: string;
@ApiPropertyOptional({ deprecated: true })
auth_parameters: AuthParameters;
@ApiPropertyOptional({ deprecated: true })
file_format_params: FileFormatParams;
}
export class GetAvailableEntitiesReq {
@ApiProperty()
plugin: string;
@@ -167,65 +197,8 @@ export class TestConnectionRes {
@ApiProperty()
database_tables: string[];
}
export class AuthParameters {
@ApiProperty()
aws_access_key_id: string;
@ApiProperty()
aws_secret_access_key: string;
}
export class CreateInputReq {
@ApiProperty({ type: [TableColumns] })
tables: TableColumns[];
@ApiProperty()
name: string;
@ApiProperty()
description: string;
@ApiProperty()
plugin: string;
@ApiPropertyOptional()
type: string;
//deprecated attributes (for retro compatibility)
@ApiPropertyOptional({ deprecated: true })
category: string;
@ApiPropertyOptional({ deprecated: true })
credentials: Credentials;
@ApiPropertyOptional({ deprecated: true })
options: InputOptions;
@ApiPropertyOptional({ deprecated: true })
info: Info;
@ApiPropertyOptional({ deprecated: true })
cron: string;
@ApiPropertyOptional({ deprecated: true })
source_bucket: string;
@ApiPropertyOptional({ deprecated: true })
source_prefix: string;
@ApiPropertyOptional({ deprecated: true })
auth_parameters: AuthParameters;
@ApiPropertyOptional({ deprecated: true })
file_format_params: FileFormatParams;
}
export class Input {
@ApiProperty()
id: string;
@ApiProperty()
category: string;
@ApiProperty()
plugin: string;
@ApiProperty()
name: string;
@ApiProperty()
cron: string;
@ApiProperty()
credentials: Credentials;
@ApiProperty()
client_id: string;
@ApiProperty()
created_at: string;
@ApiProperty()
updated_at: string;
@ApiPropertyOptional()
info: Info;
}
export class CreateInputReq extends OmitType(Input, [
'id',
'created_at',
'updated_at',
]) {}
+9 -25
View File
@@ -149,6 +149,7 @@ export class InputsService {
return response;
},
};
secondsInADay = 60 * 60 * 24;
secondsInAnHour = 60 * 60;
@@ -163,6 +164,12 @@ export class InputsService {
}
if (payload.input_s3) return payload.input_s3;
if (payload.input_jdbc) return payload.input_jdbc;
const { credentials } = payload;
return {
...payload,
credentials: credentials && JSON.parse(credentials),
};
}
return payload;
}
@@ -216,9 +223,11 @@ export class InputsService {
const adjustedInput = this.adjustInputPayload(input);
return { input: adjustedInput };
}
async getAvailableEntities(data): Promise<{ entities: string[] }> {
return await this.OLD_inputClient.getAvailableEntities(data);
}
async findAll(info: Info) {
const { inputs } = await lastValueFrom(
this.inputReadService.InputFindAll({ info }),
@@ -227,31 +236,6 @@ export class InputsService {
const inputsReturn = inputs.map((i) => this.adjustInputPayload(i));
return { inputs: inputsReturn };
// findAll: async (data) => {
// this.logger.info('InputClientService - FindAll');
// const findAllInputResponse = await lastValueFrom(
// this.inputReadService.InputFindAll(data),
// ).catch((e) => {
// this.logger.error(e.details);
// throw new HttpException(e.details, HttpStatus.INTERNAL_SERVER_ERROR);
// });
// findAllInputResponse.inputs.forEach((input) => objectCamelToSnake(input));
// return findAllInputResponse;
// },
// try {
// const findAllInputResponse: any = await this.OLD_inputClient.findAll(
// body,
// );
// if (findAllInputResponse?.inputs?.length) {
// findAllInputResponse.inputs = findAllInputResponse.inputs.map((input) =>
// this.adjustInputPayload(input),
// );
// }
// return findAllInputResponse;
// } catch (err) {
// throw new HttpException(err.message, HttpStatus.NOT_FOUND);
// }
}
async findOne(idRequest: IIdRequest) {