mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-07 09:29:07 +00:00
124 lines
3.2 KiB
TypeScript
124 lines
3.2 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 { OutputsClientService } from 'src/clients/outputs/client.service';
|
|
import { AuthenticateCondition } from 'src/authentication/authentication.decorator';
|
|
import { PERMISSIONS } from '../../authentication/permissions.enum';
|
|
import { OutputsService } from './outputs.service';
|
|
import { DadosferaLogger } from 'dadosfera-logs';
|
|
|
|
@ApiTags('Outputs')
|
|
@Controller('outputs')
|
|
@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.OUTPUT.permissions[action].seqid,
|
|
);
|
|
})
|
|
export class OutputsController {
|
|
logger: any;
|
|
constructor(
|
|
@Inject(DadosferaLogger)
|
|
dadosferaLogger: DadosferaLogger,
|
|
private outputsClientService: OutputsClientService,
|
|
) {
|
|
this.logger = dadosferaLogger.logger;
|
|
}
|
|
|
|
@Post()
|
|
async create(@Body() createOutputDto) {
|
|
this.logger.info(process.env.DEV_URL + `/output - ON CREATE ROUTE`, {
|
|
user: createOutputDto.info.user_id,
|
|
customer: createOutputDto.info.customer,
|
|
});
|
|
|
|
const outputService = new OutputsService(this.outputsClientService);
|
|
const response = await outputService.create(createOutputDto);
|
|
|
|
return response;
|
|
}
|
|
|
|
@Get()
|
|
async findAll(@Body() data) {
|
|
this.logger.info(process.env.DEV_URL + `/output - ON Find All ROUTE`, {
|
|
user: data.info.user_id,
|
|
customer: data.info.customer,
|
|
});
|
|
|
|
const outputService = new OutputsService(this.outputsClientService);
|
|
const response = await outputService.findAll(data);
|
|
|
|
return response;
|
|
}
|
|
|
|
@Get('/:id')
|
|
async findOne(@Body() data, @Param() params) {
|
|
const { id } = params;
|
|
this.logger.info(
|
|
process.env.DEV_URL + `/output/${id} - ON Find One ROUTE`,
|
|
{
|
|
user: data.info.user_id,
|
|
customer: data.info.customer,
|
|
},
|
|
);
|
|
|
|
const outputService = new OutputsService(this.outputsClientService);
|
|
const response = await outputService.findOne({ id, ...data });
|
|
|
|
return response;
|
|
}
|
|
|
|
@Put(':id')
|
|
async update(@Payload() updateOutputDto, @Param() params) {
|
|
const { id } = params;
|
|
const { info } = updateOutputDto;
|
|
this.logger.info(process.env.DEV_URL + `/output/${id} - ON UPDATE ROUTE`, {
|
|
user: updateOutputDto.info.user_id,
|
|
customer: updateOutputDto.info.customer,
|
|
});
|
|
delete updateOutputDto.info;
|
|
|
|
const outputService = new OutputsService(this.outputsClientService);
|
|
const response = await outputService.update(id, updateOutputDto, info);
|
|
|
|
return response;
|
|
}
|
|
|
|
@Delete(':id')
|
|
async delete(@Body() data, @Param() params) {
|
|
const { id } = params;
|
|
this.logger.info(process.env.DEV_URL + `/output/${id} - ON DELETE ROUTE`, {
|
|
user: data.info.user_id,
|
|
customer: data.info.customer,
|
|
});
|
|
|
|
const outputService = new OutputsService(this.outputsClientService);
|
|
const response = await outputService.remove({ id, ...data });
|
|
|
|
return response;
|
|
}
|
|
}
|