merge with main

This commit is contained in:
rodrigo.zamboni
2022-06-29 12:28:00 -03:00
51 changed files with 4704 additions and 1168 deletions
+4
View File
@@ -1,5 +1,6 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Info } from 'src/clients/inputs/interfaces';
import { Method } from 'axios';
export class InputModel {
category: string;
@@ -15,6 +16,7 @@ export class InputModel {
options?: {
oauth?: {
get_tokens_url: string;
get_tokens_method?: Method;
get_tokens_url_params: string;
get_tokens_set_response: Record<string, string>;
content_type: string;
@@ -173,6 +175,8 @@ export class TestConnectionRes {
database_tables: string[];
}
export class CreateInputReq {
@ApiPropertyOptional()
id: string;
@ApiProperty()
plugin: string;
@ApiProperty()
+49 -16
View File
@@ -12,6 +12,8 @@ import { InputsService } from './inputs.service';
import { DadosferaLogger } from 'dadosfera-logs';
import { InputsClientService } from 'src/clients/inputs/client.service';
import { UpdateInputRequest } from 'src/clients/inputs/interfaces';
import { Permissions } from '../../authentication/permissions.enum';
import { AuthenticateCondition } from 'src/authentication/authentication.decorator';
import { ApiOkResponse, ApiTags } from '@nestjs/swagger';
import {
CreateInputReq,
@@ -26,6 +28,35 @@ import {
@ApiTags('inputs')
@Controller('inputs')
@AuthenticateCondition((req, user) => {
let action: any;
switch (req.method) {
case 'POST':
action = 'CREATE';
break;
case 'PUT':
action = 'UPDATE';
break;
case 'PATCH':
action = 'UPDATE_PARTIAL';
break;
default:
action = req.method;
}
if (
`${req.method} ${req.route.path}` ===
'GET /inputs/available-entities/:plugin'
) {
action = 'GET_ENTITIES';
}
return user.permissions.includes(Permissions.INPUT[action].seqid);
})
export class InputsController {
inputService: InputsService;
logger: any;
@@ -57,8 +88,7 @@ export class InputsController {
customer: data.info.customer,
});
const inputService = new InputsService(this.inputsClientService);
const response = await inputService.testConnection(data);
const response = await this.inputService.testConnection(data);
return response;
}
@@ -74,8 +104,7 @@ export class InputsController {
},
);
const inputService = new InputsService(this.inputsClientService);
const response = await inputService.getColumns(data);
const response = await this.inputService.getColumns(data);
return response;
}
@@ -88,8 +117,18 @@ export class InputsController {
customer: createInputDto.info.customer,
});
const inputService = new InputsService(this.inputsClientService);
const response = await inputService.create(createInputDto);
const response = await this.inputService.create(createInputDto);
return response;
}
@Post(':id')
@ApiOkResponse({ type: Input })
async reCreate(@Param('id') id: string, @Body() input: CreateInputReq) {
if (!id) id = id;
console.log(`POST /${id}`, 'ON RECREATE ROUTE');
const response = await this.inputService.reCreate(input);
return response;
}
@@ -101,9 +140,7 @@ export class InputsController {
customer: body.info.customer,
});
const inputService = new InputsService(this.inputsClientService);
const response = await inputService.findAll(body);
const response = await this.inputService.findAll(body);
return response;
}
@@ -115,9 +152,8 @@ export class InputsController {
user: body.info.user_id,
customer: body.info.customer,
});
const inputService = new InputsService(this.inputsClientService);
const response = await inputService.findOne({ id, ...body });
const response = await this.inputService.findOne({ id, ...body });
return response;
}
@@ -132,9 +168,8 @@ export class InputsController {
user: updateInputDto.info.user_id,
customer: updateInputDto.info.costumer_id,
});
const inputService = new InputsService(this.inputsClientService);
const response = await inputService.update(id, updateInputDto, info);
const response = await this.inputService.update(id, updateInputDto, info);
return response;
}
@@ -148,9 +183,7 @@ export class InputsController {
customer: data.info.customer,
});
const inputService = new InputsService(this.inputsClientService);
const response = await inputService.remove({ id, ...data });
const response = await this.inputService.remove({ id, ...data });
return response;
}
+7
View File
@@ -75,6 +75,13 @@ export class InputsService {
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.inputClient.createGeneric(data);
const adjustedInput = this.adjustInputPayload(response.input);
return { ...response, input: adjustedInput };
}
async getAvailableEntities(data): Promise<{ entities: string[] }> {
return await this.inputClient.getAvailableEntities(data);
}