mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-09 22:39:08 +00:00
Register Connector
This commit is contained in:
@@ -0,0 +1,180 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
HttpException,
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
UploadedFile,
|
||||
UseInterceptors,
|
||||
} from '@nestjs/common';
|
||||
import { FileInterceptor } from '@nestjs/platform-express';
|
||||
import { ApiConsumes, ApiTags } from '@nestjs/swagger';
|
||||
import { ConnectorManager } from '@victorradael/protospack-v2';
|
||||
import { ConnectorClientService } from 'src/clients/connector/client.service';
|
||||
import { AddTagDto } from './dtos/add-tag';
|
||||
import { CreateConnectorDto } from './dtos/create-connector';
|
||||
import { RemoveTagDto } from './dtos/remove-tag';
|
||||
import { UpdateDto } from './dtos/update';
|
||||
|
||||
@ApiTags('connectors')
|
||||
@Controller('connectors')
|
||||
export class ConnectorController {
|
||||
constructor(private connectorClientService: ConnectorClientService) {}
|
||||
|
||||
@Post('/')
|
||||
@ApiConsumes('multipart/form-data')
|
||||
@UseInterceptors(FileInterceptor('file'))
|
||||
async uploadConnector(
|
||||
@UploadedFile() file,
|
||||
@Body() body: CreateConnectorDto,
|
||||
) {
|
||||
console.log(`/upload`, 'Upload Connector Route');
|
||||
console.log(file, body);
|
||||
|
||||
// const response = await this.connectorClientService.uploadConnector({
|
||||
// file: fileField.file,
|
||||
// connector: body.connector,
|
||||
// });
|
||||
|
||||
// console.log('X', response);
|
||||
|
||||
// return response;
|
||||
}
|
||||
|
||||
@Get('/')
|
||||
async getAllConnectors(
|
||||
@Body() body: ConnectorManager.Messages.GetAllConnectorsRequest,
|
||||
) {
|
||||
console.log(`/upload`, 'Upload Connector Route');
|
||||
const { filters, search } = body;
|
||||
|
||||
const response: any = await this.connectorClientService.getAllConnectors({
|
||||
filters,
|
||||
search,
|
||||
});
|
||||
|
||||
return {
|
||||
message: response.message,
|
||||
connector: { ...JSON.parse(response.connector) },
|
||||
};
|
||||
}
|
||||
|
||||
@Get('/:plugin')
|
||||
async getConnector(@Param('plugin') plugin: string) {
|
||||
console.log(`/upload`, 'Upload Connector Route');
|
||||
|
||||
const response: any = await this.connectorClientService.getConnector(
|
||||
plugin,
|
||||
);
|
||||
|
||||
return {
|
||||
message: response.message || 'ok',
|
||||
connector: { ...JSON.parse(response.connector) },
|
||||
};
|
||||
}
|
||||
|
||||
@Get('/:plugin/details')
|
||||
async getConnectorDetails(@Param('plugin') plugin: string) {
|
||||
console.log(`/upload`, 'Upload Connector Route');
|
||||
|
||||
const response: any = await this.connectorClientService.getConnectorDetails(
|
||||
plugin,
|
||||
);
|
||||
|
||||
return {
|
||||
message: response.message || 'ok',
|
||||
connector: { ...JSON.parse(response.connector) },
|
||||
};
|
||||
}
|
||||
|
||||
@Put('/:plugin')
|
||||
@ApiConsumes('multipart/form-data')
|
||||
async updateConnector(
|
||||
@Param('plugin') plugin: string,
|
||||
@Body() body: UpdateDto,
|
||||
) {
|
||||
console.log(`/upload`, 'Upload Connector Route');
|
||||
|
||||
const changes = body;
|
||||
|
||||
const response: any = await this.connectorClientService.updateConnector({
|
||||
plugin,
|
||||
changes: JSON.stringify(changes),
|
||||
});
|
||||
|
||||
return {
|
||||
message: response.message || 'ok',
|
||||
connector: { ...JSON.parse(response.connector) },
|
||||
};
|
||||
}
|
||||
|
||||
@Put('/:plugin/add-tag')
|
||||
async addTagOnConnector(
|
||||
@Param('plugin') plugin: string,
|
||||
@Body() body: AddTagDto,
|
||||
) {
|
||||
console.log(`/upload`, 'Upload Connector Route');
|
||||
|
||||
const { tags } = body;
|
||||
|
||||
if (!tags || !(typeof tags === 'object') || !tags.length) {
|
||||
throw new HttpException('Not found tags attributes', 400);
|
||||
}
|
||||
|
||||
const changes = { plugin, tags };
|
||||
|
||||
const response: any = await this.connectorClientService.updateConnector({
|
||||
plugin,
|
||||
changes: JSON.stringify(changes),
|
||||
});
|
||||
|
||||
return {
|
||||
message: response.message || 'ok',
|
||||
connector: { ...JSON.parse(response.connector) },
|
||||
};
|
||||
}
|
||||
|
||||
@Put('/:plugin/remove-tag')
|
||||
async removeTagOnConnector(
|
||||
@Param('plugin') plugin: string,
|
||||
@Body() body: RemoveTagDto,
|
||||
) {
|
||||
console.log(`/upload`, 'Upload Connector Route');
|
||||
|
||||
const { tags } = body;
|
||||
const remove = tags;
|
||||
|
||||
if (!remove || !(typeof remove === 'object') || !remove.length) {
|
||||
throw new HttpException('Not found remove attribute', 400);
|
||||
}
|
||||
|
||||
const changes = { plugin, remove };
|
||||
|
||||
const response: any = await this.connectorClientService.updateConnector({
|
||||
plugin,
|
||||
changes: JSON.stringify(changes),
|
||||
});
|
||||
|
||||
return {
|
||||
message: response.message || 'ok',
|
||||
connector: { ...JSON.parse(response.connector) },
|
||||
};
|
||||
}
|
||||
|
||||
@Delete('/:plugin')
|
||||
async deleteConnector(@Param('plugin') plugin: string) {
|
||||
console.log(`/upload`, 'Upload Connector Route');
|
||||
|
||||
const response: any = await this.connectorClientService.deleteConnector(
|
||||
plugin,
|
||||
);
|
||||
|
||||
return {
|
||||
message: response.message || 'ok',
|
||||
connector: { ...JSON.parse(response.connector) },
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class AddTagDto {
|
||||
@ApiProperty()
|
||||
tags: string[];
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class CreateConnectorDto {
|
||||
@ApiProperty({ format: 'binary' })
|
||||
file: string;
|
||||
|
||||
@ApiProperty()
|
||||
category: string;
|
||||
|
||||
@ApiProperty()
|
||||
plugin: string;
|
||||
|
||||
@ApiProperty()
|
||||
image: string;
|
||||
|
||||
@ApiProperty()
|
||||
docs: string;
|
||||
|
||||
@ApiProperty()
|
||||
name: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'skip_select_entities: boolean skip_select_columns: boolean;',
|
||||
})
|
||||
options: {
|
||||
skip_select_entities: boolean;
|
||||
skip_select_columns: boolean;
|
||||
};
|
||||
|
||||
@ApiProperty({
|
||||
type: 'array',
|
||||
items: {
|
||||
properties: {},
|
||||
},
|
||||
})
|
||||
connection_controls: object[];
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class RemoveTagDto {
|
||||
@ApiProperty()
|
||||
tags: string[];
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class UpdateDto {
|
||||
@ApiProperty({ format: 'binary', required: false })
|
||||
file?: string;
|
||||
|
||||
@ApiProperty({ required: false })
|
||||
category?: string;
|
||||
|
||||
@ApiProperty({ required: false })
|
||||
plugin?: string;
|
||||
|
||||
@ApiProperty({ required: false })
|
||||
image?: string;
|
||||
|
||||
@ApiProperty({ required: false })
|
||||
docs?: string;
|
||||
|
||||
@ApiProperty({ required: false })
|
||||
name?: string;
|
||||
|
||||
@ApiProperty({
|
||||
required: false,
|
||||
description: 'skip_select_entities: boolean skip_select_columns: boolean;',
|
||||
})
|
||||
options?: {
|
||||
skip_select_entities: boolean;
|
||||
skip_select_columns: boolean;
|
||||
};
|
||||
|
||||
@ApiProperty({
|
||||
required: false,
|
||||
type: 'array',
|
||||
items: {
|
||||
properties: {},
|
||||
},
|
||||
})
|
||||
connection_controls?: object[];
|
||||
}
|
||||
Reference in New Issue
Block a user