mirror of
https://github.com/dadosfera/maestro.git
synced 2026-10-06 02:59:08 +00:00
160 lines
3.8 KiB
TypeScript
160 lines
3.8 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
Inject,
|
|
Param,
|
|
Post,
|
|
Put,
|
|
Headers,
|
|
} from '@nestjs/common';
|
|
import { ApiTags } from '@nestjs/swagger';
|
|
import { AuthenticateCondition } from 'src/authentication/authentication.decorator';
|
|
import { PERMISSIONS } from '../../authentication/permissions.enum';
|
|
import { PipelinesService } from './pipelines.service';
|
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
|
import { Messages } from '@dadosfera/protospack-v2/dist/lib/PipelineV2';
|
|
import { RequestUser, User } from 'src/authentication/user.decorator';
|
|
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
|
import { pipe } from 'rxjs';
|
|
|
|
@ApiTags('Pipelines')
|
|
@Controller('pipelinesV2')
|
|
@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.PIPELINE.permissions[action].seqid,
|
|
);
|
|
})
|
|
export class PipelinesController {
|
|
logger: DadosferaLogger;
|
|
constructor(
|
|
@Inject(DadosferaLogger)
|
|
dadosferaLogger: DadosferaLogger,
|
|
private pipelinesClientService: PipelinesService,
|
|
) {
|
|
this.logger = dadosferaLogger.logger;
|
|
}
|
|
|
|
@Post()
|
|
async create(
|
|
@Headers('Dadosfera-Lang') language,
|
|
@User() user: RequestUser,
|
|
@Body() createPipelineDto: Messages.PipelineV2CreateRequest,
|
|
) {
|
|
this.logger.info(process.env.DEV_URL + `/pipelines ON CREATE ROUTE`);
|
|
const { customer_id, customer_name, username, user_id } = user;
|
|
const metadata = PackTheMetadata({
|
|
customer_id,
|
|
customer_name,
|
|
username,
|
|
user_id,
|
|
language,
|
|
});
|
|
|
|
const response = await this.pipelinesClientService.create(
|
|
createPipelineDto,
|
|
metadata,
|
|
);
|
|
|
|
return response;
|
|
}
|
|
|
|
@Get()
|
|
async findAll(
|
|
@User() user: RequestUser,
|
|
@Headers('Dadosfera-Lang') language,
|
|
@Body() data,
|
|
) {
|
|
this.logger.info(process.env.DEV_URL + `/pipeline ON Find All ROUTE`, {
|
|
user: data.info.user_id,
|
|
customer: data.info.customer,
|
|
});
|
|
|
|
const { customer_id, customer_name, user_id, username } = user;
|
|
const metadata = PackTheMetadata({
|
|
customer_id,
|
|
customer_name,
|
|
user_id,
|
|
username,
|
|
language,
|
|
});
|
|
|
|
const response = await this.pipelinesClientService.findAll(data, metadata);
|
|
|
|
return response;
|
|
}
|
|
|
|
@Get('/:id')
|
|
async findOne(
|
|
@Headers('Dadosfera-Lang') language,
|
|
@User() user: RequestUser,
|
|
@Param('id') id,
|
|
): Promise<Messages.PipelineV2FindOneResponse> {
|
|
this.logger.info(process.env.DEV_URL + `/pipeline/${id} ON Find One ROUTE`);
|
|
|
|
const { customer_id, customer_name, user_id, username } = user;
|
|
|
|
const metadata = PackTheMetadata({
|
|
customer_id,
|
|
customer_name,
|
|
user_id,
|
|
username,
|
|
language,
|
|
});
|
|
|
|
const result = await this.pipelinesClientService.findOne({ id }, metadata);
|
|
|
|
Object.assign(result.pipeline, {
|
|
transformations: JSON.parse(result.pipeline.transformations),
|
|
config: {
|
|
cron: result.pipeline.config.cron,
|
|
tables: JSON.parse(result.pipeline.config.tables),
|
|
},
|
|
});
|
|
|
|
return result;
|
|
}
|
|
|
|
@Put('/:id')
|
|
async update(@Body() updatePipelineDto, @Param('id') id) {
|
|
const { info } = updatePipelineDto;
|
|
delete updatePipelineDto.info;
|
|
|
|
this.logger.info(process.env.DEV_URL + `/pipeline/${id} ON UPDATE ROUTE`);
|
|
|
|
const response = await this.pipelinesClientService.update({
|
|
...updatePipelineDto,
|
|
info,
|
|
id,
|
|
});
|
|
|
|
return response;
|
|
}
|
|
|
|
@Delete(':id')
|
|
async delete(@Body() data, @Param() params) {
|
|
const { id } = params;
|
|
this.logger.info(process.env.DEV_URL + `/pipeline/${id} ON DELETE ROUTE`);
|
|
|
|
const response = await this.pipelinesClientService.remove({ id, ...data });
|
|
|
|
return response;
|
|
}
|
|
}
|