mirror of
https://github.com/dadosfera/maestro.git
synced 2026-09-17 20:54:47 +00:00
199 lines
5.1 KiB
TypeScript
199 lines
5.1 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Post,
|
|
Inject,
|
|
Put,
|
|
Param,
|
|
Delete,
|
|
Get,
|
|
Headers,
|
|
Query,
|
|
} from '@nestjs/common';
|
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
|
import { ConnectionClientService } from './client.service';
|
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
|
import {
|
|
Authenticated,
|
|
RequireAllPermissions,
|
|
} from 'src/authentication/authentication.decorator';
|
|
import { PERMISSIONS } from 'src/authentication/permissions.enum';
|
|
import { RequestUser, User } from 'src/authentication/user.decorator';
|
|
import { ValidationPipe } from '../../pipes/object-validation.pipe';
|
|
import {
|
|
ConnectionDetailsRes,
|
|
ConnectionRes,
|
|
ConnectionsRes,
|
|
UpdateConnectionDto,
|
|
} from './dtos/connection';
|
|
import { CreateConnectionDto } from './dtos/connection';
|
|
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
|
|
|
@ApiTags('connections')
|
|
@ApiBearerAuth()
|
|
@Authenticated()
|
|
@Controller('connections')
|
|
export class ConnectionController {
|
|
logger: any;
|
|
constructor(
|
|
@Inject(DadosferaLogger)
|
|
dadosferaLogger: DadosferaLogger,
|
|
private clientService: ConnectionClientService,
|
|
) {
|
|
this.logger = dadosferaLogger.logger;
|
|
}
|
|
|
|
@Post()
|
|
// @RequireAllPermissions(Permissions.CONNECTIONS.CREATE)
|
|
async createConnection(
|
|
@User() user: RequestUser,
|
|
@Body(new ValidationPipe()) body: CreateConnectionDto,
|
|
): Promise<ConnectionRes> {
|
|
this.logger.info('/connections - Create Connection');
|
|
|
|
const { user_id, customer_id, customer_name, username } = user;
|
|
const metadata = PackTheMetadata({
|
|
user_id,
|
|
customer_id,
|
|
customer_name,
|
|
username,
|
|
});
|
|
|
|
const response: any = await this.clientService.createConnection(
|
|
body,
|
|
metadata,
|
|
);
|
|
|
|
return response;
|
|
}
|
|
|
|
@Put('/:id')
|
|
// @RequireAllPermissions(Permissions.CONNECTIONS.CREATE)
|
|
async updateConnection(
|
|
@User() user: RequestUser,
|
|
@Headers('Dadosfera-Lang') language: string,
|
|
@Param('id') id: string,
|
|
@Body(new ValidationPipe()) body: UpdateConnectionDto,
|
|
): Promise<ConnectionRes> {
|
|
this.logger.info('/connections - Update Connection');
|
|
|
|
const { user_id, customer_id, customer_name, username } = user;
|
|
const metadata = PackTheMetadata({
|
|
user_id,
|
|
customer_id,
|
|
customer_name,
|
|
language,
|
|
username,
|
|
});
|
|
|
|
const response: any = await this.clientService.updateConnection(
|
|
id,
|
|
body,
|
|
metadata,
|
|
);
|
|
|
|
return response;
|
|
}
|
|
|
|
@Delete('/:id')
|
|
// @RequireAllPermissions(Permissions.CONNECTIONS.CREATE)
|
|
async deleteConnection(
|
|
@User() user: RequestUser,
|
|
@Param('id') id: string,
|
|
): Promise<ConnectionRes> {
|
|
this.logger.info('/connections - Delete Connection');
|
|
|
|
const { user_id, customer_id, customer_name, username } = user;
|
|
const metadata = PackTheMetadata({
|
|
user_id,
|
|
customer_id,
|
|
customer_name,
|
|
username,
|
|
});
|
|
|
|
const response: any = await this.clientService.deleteConnection({
|
|
body: { id },
|
|
metadata,
|
|
});
|
|
|
|
return response;
|
|
}
|
|
|
|
@Get()
|
|
// @RequireAllPermissions(Permissions.CONNECTIONS.CREATE)
|
|
async getAllConnection(
|
|
@User() user: RequestUser,
|
|
@Headers('Dadosfera-Lang') language,
|
|
@Query() queries,
|
|
): Promise<ConnectionsRes> {
|
|
this.logger.info('/connections - Get All Connection');
|
|
|
|
const { user_id, customer_id, customer_name, username } = user;
|
|
const { search, size, page, ...filters } = queries;
|
|
const metadata = PackTheMetadata({
|
|
user_id,
|
|
customer_id,
|
|
customer_name,
|
|
language,
|
|
username,
|
|
});
|
|
|
|
const response = await this.clientService.getAllConnection({
|
|
body: { search, size, page, filters },
|
|
metadata,
|
|
});
|
|
|
|
return response;
|
|
}
|
|
|
|
@Get('/:id')
|
|
// @RequireAllPermissions(Permissions.CONNECTIONS.CREATE)
|
|
async getConnectionDetails(
|
|
@User() user: RequestUser,
|
|
@Param('id') id,
|
|
@Query('details') details,
|
|
): Promise<ConnectionDetailsRes> {
|
|
this.logger.info('/connections - Get Connection Details');
|
|
|
|
const { user_id, customer_id, customer_name, username } = user;
|
|
const metadata = PackTheMetadata({
|
|
user_id,
|
|
customer_id,
|
|
customer_name,
|
|
username,
|
|
details,
|
|
});
|
|
|
|
const response: any = await this.clientService.getConnectionDetails({
|
|
body: { id },
|
|
metadata,
|
|
});
|
|
|
|
if (details === 'true') {
|
|
const properties = JSON.parse(response.connection.properties);
|
|
|
|
properties.connection_controls.map((cont) => {
|
|
if (cont.default_value != false) {
|
|
cont.default_value = JSON.parse(cont.default_value);
|
|
}
|
|
});
|
|
|
|
Object.assign(response.connection, {
|
|
pipelines: JSON.parse(response.connection.pipelines),
|
|
connection_controls: properties.connection_controls,
|
|
config_controls: properties.config_controls,
|
|
connection_steps: properties.connection_steps,
|
|
});
|
|
|
|
delete response.connection.properties;
|
|
} else {
|
|
Object.assign(response.connection, {
|
|
properties: JSON.parse(response.connection.properties),
|
|
pipelines: JSON.parse(response.connection.pipelines),
|
|
});
|
|
}
|
|
|
|
return response;
|
|
}
|
|
}
|