mirror of
https://github.com/dadosfera/maestro.git
synced 2026-09-01 04:08:16 +00:00
128 lines
3.6 KiB
TypeScript
128 lines
3.6 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
Inject,
|
|
Param,
|
|
Post,
|
|
Put,
|
|
} from '@nestjs/common';
|
|
import { ApiTags } from '@nestjs/swagger';
|
|
import { TransformationsClientService } from './client.service';
|
|
import { IIdRequest } from './interfaces';
|
|
import {
|
|
AuthenticateCondition,
|
|
Authenticated,
|
|
RequireSomePermission,
|
|
} from 'src/authentication/authentication.decorator';
|
|
import { PERMISSIONS_GROUPS } from '../../authentication/permissions.enum';
|
|
import { TransformationsService } from './transformations.service';
|
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
|
import { RequestUser, User } from 'src/authentication/user.decorator';
|
|
const pipelinePermissions = PERMISSIONS_GROUPS.PIPELINE.permissions;
|
|
@ApiTags('Transformations')
|
|
@Controller('transformations')
|
|
@Authenticated()
|
|
export class TransformationsController {
|
|
logger: DadosferaLogger;
|
|
constructor(
|
|
@Inject(DadosferaLogger)
|
|
dadosferaLogger: DadosferaLogger,
|
|
private transformationsClientService: TransformationsClientService,
|
|
) {
|
|
this.logger = dadosferaLogger.logger;
|
|
}
|
|
|
|
@Post()
|
|
@RequireSomePermission(pipelinePermissions.CREATE, pipelinePermissions.UPDATE)
|
|
async create(@Body() createTransformationDto) {
|
|
this.logger.info(`/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()
|
|
@RequireSomePermission(pipelinePermissions.GET)
|
|
async findAll(@Body() data: IIdRequest) {
|
|
this.logger.info(`/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')
|
|
@RequireSomePermission(pipelinePermissions.GET)
|
|
async findOne(@Body() data, @Param() params) {
|
|
const { id } = params;
|
|
this.logger.info(`/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')
|
|
@RequireSomePermission(pipelinePermissions.CREATE, pipelinePermissions.UPDATE)
|
|
async update(
|
|
@User() user: RequestUser,
|
|
@Body() updateTransformationDto,
|
|
@Param('id') id: string,
|
|
) {
|
|
this.logger.info(`/transformation/${id} - ON UPDATE ROUTE`, {
|
|
user: user.user_id,
|
|
customer: user.customer_name,
|
|
});
|
|
|
|
const transformationService = new TransformationsService(
|
|
this.transformationsClientService,
|
|
);
|
|
const response = await transformationService.update(
|
|
id,
|
|
updateTransformationDto,
|
|
);
|
|
|
|
return response;
|
|
}
|
|
|
|
@Delete(':id')
|
|
@RequireSomePermission(pipelinePermissions.CREATE, pipelinePermissions.UPDATE)
|
|
async delete(@Body() data, @Param() params) {
|
|
const { id } = params;
|
|
this.logger.info(`/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;
|
|
}
|
|
}
|