mirror of
https://github.com/dadosfera/maestro.git
synced 2026-10-14 17:19:08 +00:00
merge with main
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user