mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-13 13:39:08 +00:00
Merge branch 'ft/connection-manager' of github.com:dadosfera/maestro into ft/connection-manager
This commit is contained in:
@@ -64,4 +64,118 @@ export class ConnectionClientService implements OnModuleInit {
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
async updateConnection({ body, info }) {
|
||||
const meta = new Metadata();
|
||||
meta.add('customer_id', info.customer_id);
|
||||
meta.add('customer_name', info.customer_name);
|
||||
meta.add('user_id', info.user_id);
|
||||
|
||||
const {
|
||||
id,
|
||||
description,
|
||||
image_url,
|
||||
name,
|
||||
network_config_id,
|
||||
properties,
|
||||
type,
|
||||
} = body;
|
||||
|
||||
return lastValueFrom(
|
||||
this.connectionServiceWrite.UpdateConnection(
|
||||
{
|
||||
id,
|
||||
description,
|
||||
image_url,
|
||||
name,
|
||||
network_config_id,
|
||||
properties: JSON.stringify(properties),
|
||||
type,
|
||||
},
|
||||
meta,
|
||||
),
|
||||
).catch((err) => {
|
||||
throw new HttpException(
|
||||
err.details,
|
||||
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
async deleteConnection({ body, info }) {
|
||||
const meta = new Metadata();
|
||||
meta.add('customer_id', info.customer_id);
|
||||
meta.add('customer_name', info.customer_name);
|
||||
meta.add('user_id', info.user_id);
|
||||
|
||||
const { id } = body;
|
||||
|
||||
return lastValueFrom(
|
||||
this.connectionServiceWrite.DeleteConnection(
|
||||
{
|
||||
id,
|
||||
},
|
||||
meta,
|
||||
),
|
||||
).catch((err) => {
|
||||
throw new HttpException(
|
||||
err.details,
|
||||
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
async getAllConnection({ body, info }) {
|
||||
const meta = new Metadata();
|
||||
meta.add('customer_id', info.customer_id);
|
||||
meta.add('customer_name', info.customer_name);
|
||||
meta.add('user_id', info.user_id);
|
||||
|
||||
const { id } = body;
|
||||
|
||||
return lastValueFrom(
|
||||
this.connectionServiceRead.GetAllConnection({}, meta),
|
||||
).catch((err) => {
|
||||
throw new HttpException(
|
||||
err.details,
|
||||
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
async getConnection({ body, info }) {
|
||||
const meta = new Metadata();
|
||||
meta.add('customer_id', info.customer_id);
|
||||
meta.add('customer_name', info.customer_name);
|
||||
meta.add('user_id', info.user_id);
|
||||
|
||||
const { id } = body;
|
||||
|
||||
return lastValueFrom(
|
||||
this.connectionServiceRead.GetConnection({ id }, meta),
|
||||
).catch((err) => {
|
||||
throw new HttpException(
|
||||
err.details,
|
||||
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
async getConnectionDetails({ body, info }) {
|
||||
const meta = new Metadata();
|
||||
meta.add('customer_id', info.customer_id);
|
||||
meta.add('customer_name', info.customer_name);
|
||||
meta.add('user_id', info.user_id);
|
||||
|
||||
const { id } = body;
|
||||
|
||||
return lastValueFrom(
|
||||
this.connectionServiceRead.GetConnectionDetails({ id }, meta),
|
||||
).catch((err) => {
|
||||
throw new HttpException(
|
||||
err.details,
|
||||
err.code === 6 ? HttpStatus.CONFLICT : 400,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,13 @@
|
||||
import { Body, Controller, Post, Inject } from '@nestjs/common';
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Post,
|
||||
Inject,
|
||||
Put,
|
||||
Param,
|
||||
Delete,
|
||||
Get,
|
||||
} from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { ConnectionClientService } from './client.service';
|
||||
import { CreateConnectionDto } from './dtos/create-connection';
|
||||
@@ -10,6 +19,8 @@ import {
|
||||
import { Permissions } from 'src/authentication/permissions.enum';
|
||||
import { User } from 'src/authentication/user.decorator';
|
||||
import { ValidationPipe } from '../../pipes/object-validation.pipe';
|
||||
import { UpdateConnectionDto } from './dtos/update-connection';
|
||||
import { identity } from 'rxjs';
|
||||
|
||||
@ApiTags('connections')
|
||||
@ApiBearerAuth()
|
||||
@@ -48,4 +59,100 @@ export class ConnectionController {
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@Put('/:id')
|
||||
// @RequireAllPermissions(Permissions.CONNECTIONS.CREATE)
|
||||
async updateConnection(
|
||||
@User() user,
|
||||
@Param('id') id,
|
||||
@Body(new ValidationPipe()) body: UpdateConnectionDto,
|
||||
) {
|
||||
this.logger.info('/connections - Update Connection');
|
||||
|
||||
const { user_id, customer_id, customer_name } = user;
|
||||
|
||||
const response = await this.clientService.updateConnection({
|
||||
body: { ...body, id },
|
||||
info: { user_id, customer_id, customer_name },
|
||||
});
|
||||
|
||||
delete response.connection.properties;
|
||||
delete response.connection.user_id;
|
||||
delete response.connection.customer_id;
|
||||
delete response.connection.customer_name;
|
||||
delete response.connection.updated_at;
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@Delete('/:id')
|
||||
// @RequireAllPermissions(Permissions.CONNECTIONS.CREATE)
|
||||
async deleteConnection(@User() user, @Param('id') id) {
|
||||
this.logger.info('/connections - Delete Connection');
|
||||
|
||||
const { user_id, customer_id, customer_name } = user;
|
||||
|
||||
const response = await this.clientService.deleteConnection({
|
||||
body: { id },
|
||||
info: { user_id, customer_id, customer_name },
|
||||
});
|
||||
|
||||
delete response.connection.properties;
|
||||
delete response.connection.user_id;
|
||||
delete response.connection.customer_id;
|
||||
delete response.connection.customer_name;
|
||||
delete response.connection.updated_at;
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@Get()
|
||||
// @RequireAllPermissions(Permissions.CONNECTIONS.CREATE)
|
||||
async getAllConnection(@User() user) {
|
||||
this.logger.info('/connections - Get All Connection');
|
||||
|
||||
const { user_id, customer_id, customer_name } = user;
|
||||
|
||||
const response = await this.clientService.getAllConnection({
|
||||
body: {},
|
||||
info: { user_id, customer_id, customer_name },
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@Get('/:id')
|
||||
// @RequireAllPermissions(Permissions.CONNECTIONS.CREATE)
|
||||
async getConnection(@User() user, @Param('id') id) {
|
||||
this.logger.info('/connections - Get Connection');
|
||||
|
||||
const { user_id, customer_id, customer_name } = user;
|
||||
|
||||
const response = await this.clientService.getConnection({
|
||||
body: { id },
|
||||
info: { user_id, customer_id, customer_name },
|
||||
});
|
||||
|
||||
delete response.connection.user_id;
|
||||
delete response.connection.customer_id;
|
||||
delete response.connection.customer_name;
|
||||
delete response.connection.updated_at;
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@Get('/:id/details')
|
||||
// @RequireAllPermissions(Permissions.CONNECTIONS.CREATE)
|
||||
async getConnectionDetails(@User() user, @Param('id') id) {
|
||||
this.logger.info('/connections - Get Connection Details');
|
||||
|
||||
const { user_id, customer_id, customer_name } = user;
|
||||
|
||||
const response = await this.clientService.getConnectionDetails({
|
||||
body: { id },
|
||||
info: { user_id, customer_id, customer_name },
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsString, IsObject, IsOptional } from 'class-validator';
|
||||
|
||||
export class UpdateConnectionDto {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
name: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
description: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
network_config_id: string;
|
||||
|
||||
@ApiProperty()
|
||||
@IsObject()
|
||||
@IsOptional()
|
||||
properties: any;
|
||||
}
|
||||
Reference in New Issue
Block a user