mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-12 12:59:09 +00:00
Prepared Outputs and Transformations to use info params given by auth
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import { Controller, Inject, OnModuleInit } from '@nestjs/common';
|
||||
import { ClientGrpc, Payload } from '@nestjs/microservices';
|
||||
import { OutputsServiceInterface } from '@victorradael/protospack';
|
||||
import { objectCamelToSnake } from 'src/utils/CaseConverter';
|
||||
import {
|
||||
objectCamelToSnake,
|
||||
objectSnakeToCamel,
|
||||
} from 'src/utils/CaseConverter';
|
||||
import {
|
||||
ICreateOutputRequest,
|
||||
IIdRequest,
|
||||
@@ -24,7 +27,7 @@ export class OutputsClientService implements OnModuleInit {
|
||||
console.log('OutputClientService', 'Create');
|
||||
|
||||
const createOutputResponse = await new Promise((resolve, reject) => {
|
||||
this.outputService.Create(createOutputDto).subscribe({
|
||||
this.outputService.Create(objectSnakeToCamel(createOutputDto)).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
@@ -47,11 +50,11 @@ export class OutputsClientService implements OnModuleInit {
|
||||
return createOutputResponse;
|
||||
}
|
||||
|
||||
async findAll() {
|
||||
async findAll(data) {
|
||||
console.log('OutputClientService', 'FindAll');
|
||||
|
||||
const findAllOutputResponse = await new Promise((resolve, reject) => {
|
||||
this.outputService.FindAll({}).subscribe({
|
||||
this.outputService.FindAll(objectSnakeToCamel(data)).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
@@ -76,11 +79,11 @@ export class OutputsClientService implements OnModuleInit {
|
||||
return { outputs: convertedOutputs };
|
||||
}
|
||||
|
||||
async findOne({ id }: IIdRequest) {
|
||||
async findOne(data: IIdRequest) {
|
||||
console.log('OutputClientService', 'FindOne');
|
||||
|
||||
const findOneOutputResponse = await new Promise((resolve, reject) => {
|
||||
this.outputService.FindOne({ id }).subscribe({
|
||||
this.outputService.FindOne(objectSnakeToCamel(data)).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
@@ -105,7 +108,7 @@ export class OutputsClientService implements OnModuleInit {
|
||||
console.log('OutputClientService', 'Update');
|
||||
|
||||
const updateOutputResponse = await new Promise((resolve, reject) => {
|
||||
this.outputService.Update(updateOutPutDTO).subscribe({
|
||||
this.outputService.Update(objectSnakeToCamel(updateOutPutDTO)).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
@@ -126,11 +129,11 @@ export class OutputsClientService implements OnModuleInit {
|
||||
return objectCamelToSnake(updateOutputResponse);
|
||||
}
|
||||
|
||||
async remove({ id }: IIdRequest) {
|
||||
async remove(data: IIdRequest) {
|
||||
console.log('OutputClientService', 'Remove');
|
||||
|
||||
const removeOutputResponse = await new Promise((resolve, reject) => {
|
||||
this.outputService.Remove({ id }).subscribe({
|
||||
this.outputService.Remove(objectSnakeToCamel(data)).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
|
||||
Vendored
+7
@@ -9,8 +9,14 @@ export interface Values {
|
||||
prefix: string;
|
||||
}
|
||||
|
||||
interface Info {
|
||||
user_id: string;
|
||||
customer_id: string;
|
||||
}
|
||||
|
||||
export interface IIdRequest {
|
||||
id: string;
|
||||
info: Info;
|
||||
}
|
||||
|
||||
export interface IOutputUpdateRequest {
|
||||
@@ -19,4 +25,5 @@ export interface IOutputUpdateRequest {
|
||||
values: Values;
|
||||
plugin: string;
|
||||
name: string;
|
||||
info: Info;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { Controller, Inject, OnModuleInit, Post } from '@nestjs/common';
|
||||
import { ClientGrpc } from '@nestjs/microservices';
|
||||
import { TransformationsServiceInterface } from '@victorradael/protospack';
|
||||
import { objectCamelToSnake } from 'src/utils/CaseConverter';
|
||||
import { ICreateTransformationsRequest, IdRequest } from './interfaces';
|
||||
import {
|
||||
objectCamelToSnake,
|
||||
objectSnakeToCamel,
|
||||
} from 'src/utils/CaseConverter';
|
||||
import { ICreateTransformationsRequest, IIdRequest } from './interfaces';
|
||||
|
||||
@Controller('transformation')
|
||||
export class TransformationsClientService implements OnModuleInit {
|
||||
@@ -24,18 +27,20 @@ export class TransformationsClientService implements OnModuleInit {
|
||||
|
||||
const createTransformationResponse = await new Promise(
|
||||
(resolve, reject) => {
|
||||
this.transformationService.create(createTransformationsDto).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
error(err) {
|
||||
console.log('Observable Error');
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
console.log('done');
|
||||
},
|
||||
});
|
||||
this.transformationService
|
||||
.create(objectSnakeToCamel(createTransformationsDto))
|
||||
.subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
error(err) {
|
||||
console.log('Observable Error');
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
console.log('done');
|
||||
},
|
||||
});
|
||||
},
|
||||
)
|
||||
.then((res) => res)
|
||||
@@ -52,12 +57,12 @@ export class TransformationsClientService implements OnModuleInit {
|
||||
return { transformations: convertedTransforms };
|
||||
}
|
||||
|
||||
async findAll() {
|
||||
async findAll(data) {
|
||||
console.log('TransformationClientService', 'FindAll');
|
||||
|
||||
const findAllTransformationResponse = await new Promise(
|
||||
(resolve, reject) => {
|
||||
this.transformationService.findAll({}).subscribe({
|
||||
this.transformationService.findAll(objectSnakeToCamel(data)).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
@@ -83,12 +88,12 @@ export class TransformationsClientService implements OnModuleInit {
|
||||
return { transformations: convertedTransforms };
|
||||
}
|
||||
|
||||
async findOne({ id }: IdRequest) {
|
||||
async findOne(data: IIdRequest) {
|
||||
console.log('TransformationClientService', 'FindOne');
|
||||
|
||||
const findOneTransformationResponse = await new Promise(
|
||||
(resolve, reject) => {
|
||||
this.transformationService.findOne({ id }).subscribe({
|
||||
this.transformationService.findOne(objectSnakeToCamel(data)).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
@@ -115,18 +120,20 @@ export class TransformationsClientService implements OnModuleInit {
|
||||
|
||||
const updateTransformationResponse = await new Promise(
|
||||
(resolve, reject) => {
|
||||
this.transformationService.update(updateTransformationDTO).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
error(err) {
|
||||
console.log('Observable Error');
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
console.log('done');
|
||||
},
|
||||
});
|
||||
this.transformationService
|
||||
.update(objectSnakeToCamel(updateTransformationDTO))
|
||||
.subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
error(err) {
|
||||
console.log('Observable Error');
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
console.log('done');
|
||||
},
|
||||
});
|
||||
},
|
||||
)
|
||||
.then((res) => res)
|
||||
@@ -137,12 +144,12 @@ export class TransformationsClientService implements OnModuleInit {
|
||||
return objectCamelToSnake(updateTransformationResponse);
|
||||
}
|
||||
|
||||
async remove({ id }: IdRequest) {
|
||||
async remove(data: IIdRequest) {
|
||||
console.log('TransformationClientService', 'Remove');
|
||||
|
||||
const removeTransformationResponse = await new Promise(
|
||||
(resolve, reject) => {
|
||||
this.transformationService.remove({ id }).subscribe({
|
||||
this.transformationService.remove(objectSnakeToCamel(data)).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
|
||||
+10
-1
@@ -1,5 +1,6 @@
|
||||
export interface ICreateTransformationsRequest {
|
||||
transformations: Transformation[];
|
||||
info: Info;
|
||||
}
|
||||
interface Param {
|
||||
base_column: string;
|
||||
@@ -9,6 +10,12 @@ interface Param {
|
||||
randbelow: number;
|
||||
const: string;
|
||||
}
|
||||
|
||||
export interface Info {
|
||||
customer_id: string;
|
||||
user_id: string;
|
||||
}
|
||||
|
||||
interface Transformation {
|
||||
created_at: string;
|
||||
id: string;
|
||||
@@ -19,10 +26,12 @@ interface Transformation {
|
||||
table: string;
|
||||
}
|
||||
|
||||
export interface IdRequest {
|
||||
export interface IIdRequest {
|
||||
id: string;
|
||||
info: Info;
|
||||
}
|
||||
|
||||
export interface IUpdateTransformationRequest {
|
||||
transformation: Transformation;
|
||||
info: Info;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ export class LoggerMiddleware implements NestMiddleware {
|
||||
havePermission = true;
|
||||
}
|
||||
});
|
||||
|
||||
havePermission = true;
|
||||
if (havePermission) {
|
||||
request.body.info = {
|
||||
customer_id: clienId,
|
||||
|
||||
@@ -26,22 +26,22 @@ export class OutputsController {
|
||||
}
|
||||
|
||||
@Get()
|
||||
async findAll() {
|
||||
async findAll(@Body() data) {
|
||||
console.log(process.env.DEV_URL + `/output`, 'ON Find All ROUTE');
|
||||
|
||||
const outputService = new OutputsService(this.outputsClientService);
|
||||
const response = await outputService.findAll();
|
||||
const response = await outputService.findAll(data);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@Get('/:id')
|
||||
async findOne(@Param() params) {
|
||||
async findOne(@Body() data, @Param() params) {
|
||||
const { id } = params;
|
||||
console.log(process.env.DEV_URL + `/output/${id}`, 'ON Find One ROUTE');
|
||||
|
||||
const outputService = new OutputsService(this.outputsClientService);
|
||||
const response = await outputService.findOne(id);
|
||||
const response = await outputService.findOne({ id, ...data });
|
||||
|
||||
return response;
|
||||
}
|
||||
@@ -49,21 +49,24 @@ export class OutputsController {
|
||||
@Put(':id')
|
||||
async update(@Payload() updateOutputDto, @Param() params) {
|
||||
const { id } = params;
|
||||
const { info } = updateOutputDto;
|
||||
delete updateOutputDto.info;
|
||||
|
||||
console.log(process.env.DEV_URL + `/output/${id}`, 'ON UPDATE ROUTE');
|
||||
|
||||
const outputService = new OutputsService(this.outputsClientService);
|
||||
const response = await outputService.update(id, updateOutputDto);
|
||||
const response = await outputService.update(id, updateOutputDto, info);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
async delete(@Param() params) {
|
||||
async delete(@Body() data, @Param() params) {
|
||||
const { id } = params;
|
||||
console.log(process.env.DEV_URL + `/output/${id}`, 'ON DELETE ROUTE');
|
||||
|
||||
const outputService = new OutputsService(this.outputsClientService);
|
||||
const response = await outputService.remove(id);
|
||||
const response = await outputService.remove({ id, ...data });
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||
import { IIdRequest, Info } from 'src/clients/outputs/interfaces';
|
||||
import { OutputsClientService } from 'src/clients/outputs/client.service';
|
||||
|
||||
@Injectable()
|
||||
@@ -17,18 +18,18 @@ export class OutputsService {
|
||||
}
|
||||
}
|
||||
|
||||
async findOne(id: string) {
|
||||
async findOne(data: IIdRequest) {
|
||||
try {
|
||||
const findOneOutputResponse = await this.outputClient.findOne({ id });
|
||||
const findOneOutputResponse = await this.outputClient.findOne(data);
|
||||
return findOneOutputResponse;
|
||||
} catch (err) {
|
||||
throw new HttpException(err.message, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
async findAll() {
|
||||
async findAll(data) {
|
||||
try {
|
||||
const findAllOutputResponse = await this.outputClient.findAll();
|
||||
const findAllOutputResponse = await this.outputClient.findAll(data);
|
||||
|
||||
return findAllOutputResponse;
|
||||
} catch (err) {
|
||||
@@ -36,10 +37,11 @@ export class OutputsService {
|
||||
}
|
||||
}
|
||||
|
||||
async update(id: string, data) {
|
||||
async update(id: string, data, info: Info) {
|
||||
try {
|
||||
const updateOutputResponse = await this.outputClient.update({
|
||||
id,
|
||||
info,
|
||||
...data,
|
||||
});
|
||||
|
||||
@@ -49,9 +51,9 @@ export class OutputsService {
|
||||
}
|
||||
}
|
||||
|
||||
async remove(id: string) {
|
||||
async remove(data: IIdRequest) {
|
||||
try {
|
||||
const removeOutputResponse = await this.outputClient.remove({ id });
|
||||
const removeOutputResponse = await this.outputClient.remove(data);
|
||||
|
||||
return removeOutputResponse;
|
||||
} catch (err) {
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
} from '@nestjs/common';
|
||||
import { Payload } from '@nestjs/microservices';
|
||||
import { TransformationsClientService } from 'src/clients/transformations/client.service';
|
||||
import { IIdRequest } from 'src/clients/transformations/interfaces';
|
||||
import { TransformationsService } from './transformations.service';
|
||||
|
||||
@Controller('transformations')
|
||||
@@ -32,19 +33,19 @@ export class TransformationsController {
|
||||
}
|
||||
|
||||
@Get()
|
||||
async findAll() {
|
||||
async findAll(@Body() data: IIdRequest) {
|
||||
console.log(process.env.DEV_URL + `/transformation`, 'ON Find All ROUTE');
|
||||
|
||||
const transformationService = new TransformationsService(
|
||||
this.transformationsClientService,
|
||||
);
|
||||
const response = await transformationService.findAll();
|
||||
const response = await transformationService.findAll(data);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@Get('/:id')
|
||||
async findOne(@Param() params) {
|
||||
async findOne(@Body() data, @Param() params) {
|
||||
const { id } = params;
|
||||
console.log(
|
||||
process.env.DEV_URL + `/transformation/${id}`,
|
||||
@@ -54,7 +55,7 @@ export class TransformationsController {
|
||||
const transformationService = new TransformationsService(
|
||||
this.transformationsClientService,
|
||||
);
|
||||
const response = await transformationService.findOne(id);
|
||||
const response = await transformationService.findOne({ id, ...data });
|
||||
|
||||
return response;
|
||||
}
|
||||
@@ -79,7 +80,7 @@ export class TransformationsController {
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
async delete(@Param() params) {
|
||||
async delete(@Body() data, @Param() params) {
|
||||
const { id } = params;
|
||||
console.log(
|
||||
process.env.DEV_URL + `/transformation/${id}`,
|
||||
@@ -89,7 +90,7 @@ export class TransformationsController {
|
||||
const transformationService = new TransformationsService(
|
||||
this.transformationsClientService,
|
||||
);
|
||||
const response = await transformationService.remove(id);
|
||||
const response = await transformationService.remove({ id, ...data });
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||
import { TransformationsClientService } from 'src/clients/transformations/client.service';
|
||||
import { ICreateTransformationsRequest } from 'src/clients/transformations/interfaces';
|
||||
import {
|
||||
ICreateTransformationsRequest,
|
||||
IIdRequest,
|
||||
} from 'src/clients/transformations/interfaces';
|
||||
import { trSnakeToCamel } from 'src/utils/CaseConverter';
|
||||
|
||||
@Injectable()
|
||||
@@ -16,6 +19,7 @@ export class TransformationsService {
|
||||
const createTransformationResponse =
|
||||
await this.transformationClient.create({
|
||||
transformations: convertedDTO,
|
||||
info: createTransformationDto.info,
|
||||
});
|
||||
|
||||
return createTransformationResponse;
|
||||
@@ -24,20 +28,20 @@ export class TransformationsService {
|
||||
}
|
||||
}
|
||||
|
||||
async findOne(id: string) {
|
||||
async findOne(data: IIdRequest) {
|
||||
try {
|
||||
const findOneTransformationResponse =
|
||||
await this.transformationClient.findOne({ id });
|
||||
await this.transformationClient.findOne(data);
|
||||
return findOneTransformationResponse;
|
||||
} catch (err) {
|
||||
throw new HttpException(err.message, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
async findAll() {
|
||||
async findAll(data) {
|
||||
try {
|
||||
const findAllTransformationResponse =
|
||||
await this.transformationClient.findAll();
|
||||
await this.transformationClient.findAll(data);
|
||||
|
||||
return findAllTransformationResponse;
|
||||
} catch (err) {
|
||||
@@ -57,10 +61,10 @@ export class TransformationsService {
|
||||
}
|
||||
}
|
||||
|
||||
async remove(id: string) {
|
||||
async remove(data: IIdRequest) {
|
||||
try {
|
||||
const removeTransformationResponse =
|
||||
await this.transformationClient.remove({ id });
|
||||
await this.transformationClient.remove(data);
|
||||
|
||||
return removeTransformationResponse;
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user