mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-18 03:29:08 +00:00
CRUD Connection
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user