mirror of
https://github.com/dadosfera/maestro.git
synced 2026-09-03 21:24:49 +00:00
150 lines
3.7 KiB
TypeScript
150 lines
3.7 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
Inject,
|
|
Param,
|
|
Post,
|
|
Put,
|
|
} from '@nestjs/common';
|
|
import { Payload } from '@nestjs/microservices';
|
|
import { ApiTags } from '@nestjs/swagger';
|
|
import { TransformationsClientService } from 'src/clients/transformations/client.service';
|
|
import { IIdRequest } from 'src/clients/transformations/interfaces';
|
|
import { AuthenticateCondition } from 'src/authentication/authentication.decorator';
|
|
import { PERMISSIONS } from '../../authentication/permissions.enum';
|
|
import { TransformationsService } from './transformations.service';
|
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
|
|
|
@ApiTags('Transformations')
|
|
@Controller('transformations')
|
|
@AuthenticateCondition((req, user) => {
|
|
let action;
|
|
|
|
switch (req.method) {
|
|
case 'POST':
|
|
action = 'CREATE';
|
|
break;
|
|
|
|
case 'PUT':
|
|
action = 'UPDATE';
|
|
break;
|
|
|
|
default:
|
|
action = req.method;
|
|
}
|
|
|
|
return user.permissions.includes(
|
|
PERMISSIONS.TRANSFORMATIONS.permissions[action].seqid,
|
|
);
|
|
})
|
|
export class TransformationsController {
|
|
logger: DadosferaLogger;
|
|
constructor(
|
|
@Inject(DadosferaLogger)
|
|
dadosferaLogger: DadosferaLogger,
|
|
private transformationsClientService: TransformationsClientService,
|
|
) {
|
|
this.logger = dadosferaLogger.logger;
|
|
}
|
|
|
|
@Post()
|
|
async create(@Body() createTransformationDto) {
|
|
this.logger.info(
|
|
process.env.DEV_URL + `/transformation - ON CREATE ROUTE`,
|
|
{
|
|
user: createTransformationDto.info.user_id,
|
|
customer: createTransformationDto.info.customer,
|
|
},
|
|
);
|
|
|
|
const transformationService = new TransformationsService(
|
|
this.transformationsClientService,
|
|
);
|
|
const response = await transformationService.create(
|
|
createTransformationDto,
|
|
);
|
|
|
|
return response;
|
|
}
|
|
|
|
@Get()
|
|
async findAll(@Body() data: IIdRequest) {
|
|
this.logger.info(
|
|
process.env.DEV_URL + `/transformation - ON Find All ROUTE`,
|
|
{
|
|
user: data.info.user_id,
|
|
customer: data.info.customer_id,
|
|
},
|
|
);
|
|
|
|
const transformationService = new TransformationsService(
|
|
this.transformationsClientService,
|
|
);
|
|
const response = await transformationService.findAll(data);
|
|
|
|
return response;
|
|
}
|
|
|
|
@Get('/:id')
|
|
async findOne(@Body() data, @Param() params) {
|
|
const { id } = params;
|
|
this.logger.info(
|
|
process.env.DEV_URL + `/transformation/${id} - ON Find One ROUTE`,
|
|
{
|
|
user: data.info.user_id,
|
|
customer: data.info.customer,
|
|
},
|
|
);
|
|
|
|
const transformationService = new TransformationsService(
|
|
this.transformationsClientService,
|
|
);
|
|
const response = await transformationService.findOne({ id, ...data });
|
|
|
|
return response;
|
|
}
|
|
|
|
@Put(':id')
|
|
async update(@Payload() updateTransformationDto, @Param() params) {
|
|
const { id } = params;
|
|
this.logger.info(
|
|
process.env.DEV_URL + `/transformation/${id} - ON UPDATE ROUTE`,
|
|
{
|
|
user: updateTransformationDto.info.user_id,
|
|
customer: updateTransformationDto.info.customer,
|
|
},
|
|
);
|
|
|
|
const transformationService = new TransformationsService(
|
|
this.transformationsClientService,
|
|
);
|
|
const response = await transformationService.update(
|
|
id,
|
|
updateTransformationDto,
|
|
);
|
|
|
|
return response;
|
|
}
|
|
|
|
@Delete(':id')
|
|
async delete(@Body() data, @Param() params) {
|
|
const { id } = params;
|
|
this.logger.info(
|
|
process.env.DEV_URL + `/transformation/${id} - ON DELETE ROUTE`,
|
|
{
|
|
user: data.info.user_id,
|
|
customer: data.info.customer,
|
|
},
|
|
);
|
|
|
|
const transformationService = new TransformationsService(
|
|
this.transformationsClientService,
|
|
);
|
|
const response = await transformationService.remove({ id, ...data });
|
|
|
|
return response;
|
|
}
|
|
}
|