Prepared Outputs and Transformations to use info params given by auth

This commit is contained in:
rodrigo.zamboni
2022-03-29 17:43:44 -03:00
parent 8b19da9217
commit a3ba9c743f
9 changed files with 106 additions and 70 deletions
+39 -32
View File
@@ -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
View File
@@ -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;
}