mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-08 18:39:08 +00:00
FIX: create input generic adjusted to new pipeline format
This commit is contained in:
@@ -144,7 +144,7 @@ export class TestConnectionGetColumnsReq {
|
||||
info: Info;
|
||||
}
|
||||
export class TestConnectionGetColumnsRes {
|
||||
@ApiProperty()
|
||||
@ApiProperty({ type: [TableColumns] })
|
||||
tables: TableColumns[];
|
||||
}
|
||||
|
||||
@@ -165,19 +165,23 @@ export class TestConnectionRes {
|
||||
database_tables: string[];
|
||||
}
|
||||
export class CreateInputReq {
|
||||
@ApiPropertyOptional()
|
||||
id: string;
|
||||
@ApiProperty()
|
||||
plugin: string;
|
||||
@ApiProperty()
|
||||
category: string;
|
||||
@ApiProperty()
|
||||
credentials: Credentials;
|
||||
@ApiProperty({ type: [TableColumns] })
|
||||
tables: TableColumns[];
|
||||
@ApiProperty()
|
||||
name: string;
|
||||
@ApiProperty()
|
||||
description: string;
|
||||
@ApiProperty()
|
||||
plugin: string;
|
||||
@ApiPropertyOptional()
|
||||
type: string;
|
||||
@ApiPropertyOptional({ deprecated: true })
|
||||
category: string;
|
||||
@ApiPropertyOptional({ deprecated: true })
|
||||
credentials: Credentials;
|
||||
@ApiPropertyOptional({ deprecated: true })
|
||||
options: InputOptions;
|
||||
@ApiPropertyOptional()
|
||||
@ApiPropertyOptional({ deprecated: true })
|
||||
info: Info;
|
||||
}
|
||||
|
||||
|
||||
@@ -105,24 +105,18 @@ export class InputsController {
|
||||
|
||||
@Post()
|
||||
@ApiOkResponse({ type: Input })
|
||||
async create(@Body() createInputDto: CreateInputReq) {
|
||||
async create(@Body() body: CreateInputReq, @User() user: RequestUser) {
|
||||
const info: Info = {
|
||||
user_id: user.user_id,
|
||||
customer: user.customer_name,
|
||||
customer_id: user.customer_id,
|
||||
};
|
||||
this.logger.info(`/input - ON CREATE ROUTE`, {
|
||||
user: createInputDto.info.user_id,
|
||||
customer: createInputDto.info.customer,
|
||||
user: info.user_id,
|
||||
customer: info.customer,
|
||||
});
|
||||
|
||||
const response = await this.inputService.create(createInputDto);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@Post(':id')
|
||||
@ApiOkResponse({ type: Input })
|
||||
async reCreate(@Param('id') id: string, @Body() input: CreateInputReq) {
|
||||
if (!input.id) input.id = id;
|
||||
this.logger.info(`POST /${id}`, 'ON RECREATE ROUTE');
|
||||
|
||||
const response = await this.inputService.reCreate(input);
|
||||
const response = await this.inputService.create({ body, info });
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import {
|
||||
Body,
|
||||
ForbiddenException,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
@@ -15,12 +14,14 @@ import { objectCamelToSnake } from 'src/utils/CaseConverter';
|
||||
import { IIdRequest, UpdateInputRequest } from './dtos/old_interfaces';
|
||||
import { Input } from '@dadosfera/protospack-v2';
|
||||
import {
|
||||
InputCreateGenericRequest,
|
||||
InputCreateS3Request,
|
||||
InputNewCreateRequest,
|
||||
TestConnectionGetColumnsRequest,
|
||||
TestConnectionRequest,
|
||||
} from '@dadosfera/protospack-v2/dist/lib/Input/interfaces/messages';
|
||||
import { Info } from '@dadosfera/protospack-v2/dist/lib/Input/interfaces/entities';
|
||||
import { CreateInputReq } from './dtos/input.model';
|
||||
|
||||
@Injectable()
|
||||
|
||||
@@ -59,28 +60,6 @@ export class InputsService {
|
||||
objectCamelToSnake(input);
|
||||
return input;
|
||||
},
|
||||
createGeneric: async (createInputGeneric) => {
|
||||
this.logger.info('InputClientService - Create');
|
||||
const { info, ...data } = createInputGeneric;
|
||||
|
||||
if (data.options) delete data.options;
|
||||
if (data.credentials.oauth_code) delete data.credentials.oauth_code;
|
||||
|
||||
if (data.credentials) data.credentials = JSON.stringify(data.credentials);
|
||||
|
||||
const input = await lastValueFrom(
|
||||
this.inputWriteService.InputCreate({ info, input: data }),
|
||||
);
|
||||
// .catch((err: { details: string }) => {
|
||||
// if (err.details === 'Item Not found!') {
|
||||
// throw new NotFoundException('Input not found');
|
||||
// }
|
||||
// throw new InternalServerErrorException(err.details);
|
||||
// });
|
||||
// objectCamelToSnake(structReturn);
|
||||
// const inputCreated = DecodeGrpcStruct(structReturn.input);
|
||||
return { input };
|
||||
},
|
||||
createS3Inputs: async (createInputDto: InputCreateS3Request) => {
|
||||
this.logger.info('InputClientService - Create');
|
||||
createInputDto;
|
||||
@@ -109,80 +88,22 @@ export class InputsService {
|
||||
const updateInputResponse = await lastValueFrom(
|
||||
this.inputWriteService.InputUpdate(updateInputDTO),
|
||||
);
|
||||
// const updateInputResponse = await new Promise((resolve, reject) => {
|
||||
// this.inputWriteService.InputUpdate(updateInputDTO).subscribe({
|
||||
// next(x) {
|
||||
// resolve(objectCamelToSnake(x));
|
||||
// },
|
||||
// error(err) {
|
||||
// reject(err);
|
||||
// },
|
||||
// complete() {
|
||||
// // console.log('done');
|
||||
// },
|
||||
// });
|
||||
// })
|
||||
// .then((res) => {
|
||||
// this.logger.info('Done');
|
||||
// return res;
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// this.logger.error(err.message);
|
||||
// throw new Error(err);
|
||||
// });
|
||||
|
||||
return updateInputResponse;
|
||||
},
|
||||
remove: async (idRequest: IIdRequest) => {
|
||||
this.logger.info('InputClientService - Remove');
|
||||
|
||||
const removeInputResponse = await new Promise((resolve, reject) => {
|
||||
this.inputWriteService.InputRemove(idRequest).subscribe({
|
||||
next(x) {
|
||||
resolve(objectCamelToSnake(x));
|
||||
},
|
||||
error(err) {
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
// console.log('done');
|
||||
},
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
this.logger.info('Done');
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
this.logger.error(err.message);
|
||||
throw new Error(err);
|
||||
});
|
||||
const removeInputResponse = await lastValueFrom(
|
||||
this.inputWriteService.InputRemove(idRequest),
|
||||
);
|
||||
|
||||
return removeInputResponse;
|
||||
},
|
||||
testConnection: async (data: TestConnectionRequest) => {
|
||||
this.logger.info('InputClientService - TestConnection');
|
||||
const testConnectionResponse = await new Promise((resolve, reject) => {
|
||||
this.inputReadService.NewTestConnection(data).subscribe({
|
||||
next(x) {
|
||||
resolve(objectCamelToSnake(x));
|
||||
},
|
||||
error(err) {
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
// console.log('done');
|
||||
},
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
this.logger.info('Done');
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
this.logger.error(err.message);
|
||||
throw new Error(err);
|
||||
});
|
||||
const testConnectionResponse = await lastValueFrom(
|
||||
this.inputReadService.NewTestConnection(data),
|
||||
);
|
||||
|
||||
return testConnectionResponse;
|
||||
},
|
||||
@@ -275,40 +196,25 @@ export class InputsService {
|
||||
);
|
||||
}
|
||||
}
|
||||
async create(@Body() data) {
|
||||
this.validateCron(data);
|
||||
let response;
|
||||
switch (data.plugin.toLowerCase()) {
|
||||
case 'csv':
|
||||
case 'json':
|
||||
case 'parquet': {
|
||||
const { info, ...input } = data;
|
||||
const inputPayload = this.generateInputS3Payload(input);
|
||||
response = await this.OLD_inputClient.createS3Inputs({
|
||||
input: inputPayload,
|
||||
info,
|
||||
});
|
||||
break;
|
||||
}
|
||||
case 'oracle':
|
||||
case 'mysql':
|
||||
case 'postgresql':
|
||||
case 'sqlserver':
|
||||
response = await this.OLD_inputClient.newCreate(data);
|
||||
break;
|
||||
default:
|
||||
response = await this.OLD_inputClient.createGeneric(data);
|
||||
break;
|
||||
}
|
||||
const adjustedInput = this.adjustInputPayload(response.input);
|
||||
return { ...response, input: adjustedInput };
|
||||
}
|
||||
async reCreate(data) {
|
||||
const { info, cron } = data;
|
||||
if (cron) this.validateCron({ info, cron });
|
||||
const response = await this.OLD_inputClient.createGeneric(data);
|
||||
const adjustedInput = this.adjustInputPayload(response.input);
|
||||
return { ...response, input: adjustedInput };
|
||||
async create(data: { body: CreateInputReq; info: Info }) {
|
||||
// this.validateCron(data);
|
||||
const { body, info } = data;
|
||||
|
||||
if (body.info) delete body.info;
|
||||
|
||||
const inputCreateGenericRequest: InputCreateGenericRequest = {
|
||||
input: {
|
||||
...body,
|
||||
credentials: body.credentials && JSON.stringify(body.credentials),
|
||||
},
|
||||
info,
|
||||
};
|
||||
|
||||
const { input } = await lastValueFrom(
|
||||
this.inputWriteService.InputCreate(inputCreateGenericRequest),
|
||||
);
|
||||
const adjustedInput = this.adjustInputPayload(input);
|
||||
return { input: adjustedInput };
|
||||
}
|
||||
async getAvailableEntities(data): Promise<{ entities: string[] }> {
|
||||
return await this.OLD_inputClient.getAvailableEntities(data);
|
||||
|
||||
Reference in New Issue
Block a user