mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-11 03:29:08 +00:00
FEAT: inputs and transformation using protospack-v2
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { Controller, Inject, OnModuleInit, Post } from '@nestjs/common';
|
||||
import { ClientGrpc } from '@nestjs/microservices';
|
||||
import { TransformationsServiceInterface } from 'protospack';
|
||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||
import {
|
||||
objectCamelToSnake,
|
||||
@@ -8,10 +7,12 @@ import {
|
||||
} from 'src/utils/CaseConverter';
|
||||
import { ICreateTransformationsRequest, IIdRequest } from './interfaces';
|
||||
import { TransformationsClientConfiguration } from './transformations-client';
|
||||
import { Transformation } from '@dadosfera/protospack-v2';
|
||||
import { lastValueFrom } from 'rxjs';
|
||||
|
||||
@Controller('transformation')
|
||||
export class TransformationsClientService implements OnModuleInit {
|
||||
private transformationService: TransformationsServiceInterface;
|
||||
private transformationService: Transformation.WriteService.TransformationService;
|
||||
logger: DadosferaLogger;
|
||||
constructor(
|
||||
@Inject(DadosferaLogger)
|
||||
@@ -24,8 +25,8 @@ export class TransformationsClientService implements OnModuleInit {
|
||||
|
||||
onModuleInit() {
|
||||
this.transformationService =
|
||||
this.grpcClient.getService<TransformationsServiceInterface>(
|
||||
'TransformationService',
|
||||
this.grpcClient.getService<Transformation.WriteService.TransformationService>(
|
||||
Transformation.ProtoServices.TransformationService,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -33,31 +34,37 @@ export class TransformationsClientService implements OnModuleInit {
|
||||
async create(createTransformationsDto: ICreateTransformationsRequest) {
|
||||
this.logger.info('TransformationClientService - Create');
|
||||
|
||||
const createTransformationResponse = await new Promise(
|
||||
(resolve, reject) => {
|
||||
this.transformationService
|
||||
.Create(objectSnakeToCamel(createTransformationsDto))
|
||||
.subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
error(err) {
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
// console.log('done');
|
||||
},
|
||||
});
|
||||
},
|
||||
)
|
||||
.then((res) => {
|
||||
this.logger.info('Done');
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
this.logger.error(err.message);
|
||||
throw new Error(err);
|
||||
});
|
||||
const createTransformationResponse = await lastValueFrom(
|
||||
this.transformationService.WriteCreate(
|
||||
objectSnakeToCamel(createTransformationsDto),
|
||||
),
|
||||
);
|
||||
|
||||
// const createTransformationResponse = await new Promise(
|
||||
// (resolve, reject) => {
|
||||
// this.transformationService
|
||||
// .WriteCreate(objectSnakeToCamel(createTransformationsDto))
|
||||
// .subscribe({
|
||||
// next(x) {
|
||||
// resolve(x);
|
||||
// },
|
||||
// error(err) {
|
||||
// reject(err);
|
||||
// },
|
||||
// complete() {
|
||||
// // console.log('done');
|
||||
// },
|
||||
// });
|
||||
// },
|
||||
// )
|
||||
// .then((res) => {
|
||||
// this.logger.info('Done');
|
||||
// return res;
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// this.logger.error(err.message);
|
||||
// throw new Error(err);
|
||||
// });
|
||||
|
||||
const convertedTransforms = createTransformationResponse[
|
||||
'transformations'
|
||||
@@ -71,29 +78,33 @@ export class TransformationsClientService implements OnModuleInit {
|
||||
async findAll(data) {
|
||||
this.logger.info('TransformationClientService - FindAll');
|
||||
|
||||
const findAllTransformationResponse = await new Promise(
|
||||
(resolve, reject) => {
|
||||
this.transformationService.FindAll(objectSnakeToCamel(data)).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
error(err) {
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
// console.log('done');
|
||||
},
|
||||
});
|
||||
},
|
||||
)
|
||||
.then((res) => {
|
||||
this.logger.info('Done');
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
this.logger.error(err.message);
|
||||
throw new Error(err);
|
||||
});
|
||||
const findAllTransformationResponse = await lastValueFrom(
|
||||
this.transformationService.WriteFindAll(objectSnakeToCamel(data)),
|
||||
);
|
||||
|
||||
// const findAllTransformationResponse = await new Promise(
|
||||
// (resolve, reject) => {
|
||||
// this.transformationService.FindAll(objectSnakeToCamel(data)).subscribe({
|
||||
// next(x) {
|
||||
// resolve(x);
|
||||
// },
|
||||
// error(err) {
|
||||
// reject(err);
|
||||
// },
|
||||
// complete() {
|
||||
// // console.log('done');
|
||||
// },
|
||||
// });
|
||||
// },
|
||||
// )
|
||||
// .then((res) => {
|
||||
// this.logger.info('Done');
|
||||
// return res;
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// this.logger.error(err.message);
|
||||
// throw new Error(err);
|
||||
// });
|
||||
const convertedTransforms = findAllTransformationResponse[
|
||||
'transformations'
|
||||
].map((tr) => {
|
||||
@@ -105,29 +116,32 @@ export class TransformationsClientService implements OnModuleInit {
|
||||
async findOne(data: IIdRequest) {
|
||||
this.logger.info('TransformationClientService - FindOne');
|
||||
|
||||
const findOneTransformationResponse = await new Promise(
|
||||
(resolve, reject) => {
|
||||
this.transformationService.FindOne(objectSnakeToCamel(data)).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
error(err) {
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
// console.log('done');
|
||||
},
|
||||
});
|
||||
},
|
||||
)
|
||||
.then((res) => {
|
||||
this.logger.info('Done');
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
this.logger.error(err.message);
|
||||
throw new Error(err);
|
||||
});
|
||||
const findOneTransformationResponse = await lastValueFrom(
|
||||
this.transformationService.WriteFindOne(objectSnakeToCamel(data)),
|
||||
);
|
||||
// const findOneTransformationResponse = await new Promise(
|
||||
// (resolve, reject) => {
|
||||
// this.transformationService.FindOne(objectSnakeToCamel(data)).subscribe({
|
||||
// next(x) {
|
||||
// resolve(x);
|
||||
// },
|
||||
// error(err) {
|
||||
// reject(err);
|
||||
// },
|
||||
// complete() {
|
||||
// // console.log('done');
|
||||
// },
|
||||
// });
|
||||
// },
|
||||
// )
|
||||
// .then((res) => {
|
||||
// this.logger.info('Done');
|
||||
// return res;
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// this.logger.error(err.message);
|
||||
// throw new Error(err);
|
||||
// });
|
||||
|
||||
return objectCamelToSnake(findOneTransformationResponse);
|
||||
}
|
||||
@@ -135,31 +149,36 @@ export class TransformationsClientService implements OnModuleInit {
|
||||
async update(updateTransformationDTO) {
|
||||
this.logger.info('TransformationClientService - Update');
|
||||
|
||||
const updateTransformationResponse = await new Promise(
|
||||
(resolve, reject) => {
|
||||
this.transformationService
|
||||
.Update(objectSnakeToCamel(updateTransformationDTO))
|
||||
.subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
error(err) {
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
// console.log('done');
|
||||
},
|
||||
});
|
||||
},
|
||||
)
|
||||
.then((res) => {
|
||||
this.logger.info('Done');
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
this.logger.error(err.message);
|
||||
throw new Error(err);
|
||||
});
|
||||
const updateTransformationResponse = await lastValueFrom(
|
||||
this.transformationService.WriteUpdate(
|
||||
objectSnakeToCamel(updateTransformationDTO),
|
||||
),
|
||||
);
|
||||
// const updateTransformationResponse = await new Promise(
|
||||
// (resolve, reject) => {
|
||||
// this.transformationService
|
||||
// .Update(objectSnakeToCamel(updateTransformationDTO))
|
||||
// .subscribe({
|
||||
// next(x) {
|
||||
// resolve(x);
|
||||
// },
|
||||
// error(err) {
|
||||
// reject(err);
|
||||
// },
|
||||
// complete() {
|
||||
// // console.log('done');
|
||||
// },
|
||||
// });
|
||||
// },
|
||||
// )
|
||||
// .then((res) => {
|
||||
// this.logger.info('Done');
|
||||
// return res;
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// this.logger.error(err.message);
|
||||
// throw new Error(err);
|
||||
// });
|
||||
|
||||
return objectCamelToSnake(updateTransformationResponse);
|
||||
}
|
||||
@@ -167,29 +186,32 @@ export class TransformationsClientService implements OnModuleInit {
|
||||
async remove(data: IIdRequest) {
|
||||
this.logger.info('TransformationClientService - Remove');
|
||||
|
||||
const removeTransformationResponse = await new Promise(
|
||||
(resolve, reject) => {
|
||||
this.transformationService.Remove(objectSnakeToCamel(data)).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
error(err) {
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
// console.log('done');
|
||||
},
|
||||
});
|
||||
},
|
||||
)
|
||||
.then((res) => {
|
||||
this.logger.info('Done');
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
this.logger.error(err.message);
|
||||
throw new Error(err);
|
||||
});
|
||||
const removeTransformationResponse = await lastValueFrom(
|
||||
this.transformationService.WriteRemove(objectSnakeToCamel(data)),
|
||||
);
|
||||
// const removeTransformationResponse = await new Promise(
|
||||
// (resolve, reject) => {
|
||||
// this.transformationService.Remove(objectSnakeToCamel(data)).subscribe({
|
||||
// next(x) {
|
||||
// resolve(x);
|
||||
// },
|
||||
// error(err) {
|
||||
// reject(err);
|
||||
// },
|
||||
// complete() {
|
||||
// // console.log('done');
|
||||
// },
|
||||
// });
|
||||
// },
|
||||
// )
|
||||
// .then((res) => {
|
||||
// this.logger.info('Done');
|
||||
// return res;
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// this.logger.error(err.message);
|
||||
// throw new Error(err);
|
||||
// });
|
||||
|
||||
return objectCamelToSnake(removeTransformationResponse);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
import {
|
||||
ClientsProviderAsyncOptions,
|
||||
ClientProviderOptions,
|
||||
GrpcOptions,
|
||||
Transport,
|
||||
} from '@nestjs/microservices';
|
||||
import {
|
||||
TransformationPackages,
|
||||
TransformationProtoFilePath,
|
||||
} from 'protospack';
|
||||
import { credentials } from '@grpc/grpc-js';
|
||||
import { Transformation } from '@dadosfera/protospack-v2';
|
||||
|
||||
export class TransformationsClientConfiguration {
|
||||
public name = 'TransformationsClientConfiguration';
|
||||
@@ -15,9 +12,9 @@ export class TransformationsClientConfiguration {
|
||||
transport: Transport.GRPC,
|
||||
options: {
|
||||
url: process.env.INFACTORY_URL,
|
||||
package: TransformationPackages,
|
||||
credentials: credentials.createSsl(),
|
||||
protoPath: TransformationProtoFilePath,
|
||||
package: [Transformation.ProtoPackages.WritePackage],
|
||||
credentials: process.env.LOCAL_ENV ? undefined : credentials.createSsl(),
|
||||
protoPath: [Transformation.ProtoPaths.WriteFilePath],
|
||||
loader: {
|
||||
enums: String,
|
||||
objects: true,
|
||||
@@ -26,7 +23,7 @@ export class TransformationsClientConfiguration {
|
||||
},
|
||||
};
|
||||
|
||||
providerOptions: ClientsProviderAsyncOptions = {
|
||||
providerOptions: ClientProviderOptions = {
|
||||
name: this.name,
|
||||
...this.config,
|
||||
};
|
||||
|
||||
@@ -8,7 +8,6 @@ import {
|
||||
Post,
|
||||
Put,
|
||||
} from '@nestjs/common';
|
||||
import { Payload } from '@nestjs/microservices';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { TransformationsClientService } from './client.service';
|
||||
import { IIdRequest } from './interfaces';
|
||||
@@ -16,6 +15,7 @@ import { AuthenticateCondition } from 'src/authentication/authentication.decorat
|
||||
import { PERMISSIONS } from '../../authentication/permissions.enum';
|
||||
import { TransformationsService } from './transformations.service';
|
||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||
import { RequestUser, User } from 'src/authentication/user.decorator';
|
||||
|
||||
@ApiTags('Transformations')
|
||||
@Controller('transformations')
|
||||
@@ -51,13 +51,10 @@ export class TransformationsController {
|
||||
|
||||
@Post()
|
||||
async create(@Body() createTransformationDto) {
|
||||
this.logger.info(
|
||||
process.env.DEV_URL + `/transformation - ON CREATE ROUTE`,
|
||||
{
|
||||
user: createTransformationDto.info.user_id,
|
||||
customer: createTransformationDto.info.customer,
|
||||
},
|
||||
);
|
||||
this.logger.info(`/transformation - ON CREATE ROUTE`, {
|
||||
user: createTransformationDto.info.user_id,
|
||||
customer: createTransformationDto.info.customer,
|
||||
});
|
||||
|
||||
const transformationService = new TransformationsService(
|
||||
this.transformationsClientService,
|
||||
@@ -71,13 +68,10 @@ export class TransformationsController {
|
||||
|
||||
@Get()
|
||||
async findAll(@Body() data: IIdRequest) {
|
||||
this.logger.info(
|
||||
process.env.DEV_URL + `/transformation - ON Find All ROUTE`,
|
||||
{
|
||||
user: data.info.user_id,
|
||||
customer: data.info.customer_id,
|
||||
},
|
||||
);
|
||||
this.logger.info(`/transformation - ON Find All ROUTE`, {
|
||||
user: data.info.user_id,
|
||||
customer: data.info.customer_id,
|
||||
});
|
||||
|
||||
const transformationService = new TransformationsService(
|
||||
this.transformationsClientService,
|
||||
@@ -90,13 +84,10 @@ export class TransformationsController {
|
||||
@Get('/:id')
|
||||
async findOne(@Body() data, @Param() params) {
|
||||
const { id } = params;
|
||||
this.logger.info(
|
||||
process.env.DEV_URL + `/transformation/${id} - ON Find One ROUTE`,
|
||||
{
|
||||
user: data.info.user_id,
|
||||
customer: data.info.customer,
|
||||
},
|
||||
);
|
||||
this.logger.info(`/transformation/${id} - ON Find One ROUTE`, {
|
||||
user: data.info.user_id,
|
||||
customer: data.info.customer,
|
||||
});
|
||||
|
||||
const transformationService = new TransformationsService(
|
||||
this.transformationsClientService,
|
||||
@@ -107,15 +98,15 @@ export class TransformationsController {
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
async update(@Payload() updateTransformationDto, @Param() params) {
|
||||
const { id } = params;
|
||||
this.logger.info(
|
||||
process.env.DEV_URL + `/transformation/${id} - ON UPDATE ROUTE`,
|
||||
{
|
||||
user: updateTransformationDto.info.user_id,
|
||||
customer: updateTransformationDto.info.customer,
|
||||
},
|
||||
);
|
||||
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,
|
||||
@@ -131,13 +122,10 @@ export class TransformationsController {
|
||||
@Delete(':id')
|
||||
async delete(@Body() data, @Param() params) {
|
||||
const { id } = params;
|
||||
this.logger.info(
|
||||
process.env.DEV_URL + `/transformation/${id} - ON DELETE ROUTE`,
|
||||
{
|
||||
user: data.info.user_id,
|
||||
customer: data.info.customer,
|
||||
},
|
||||
);
|
||||
this.logger.info(`/transformation/${id} - ON DELETE ROUTE`, {
|
||||
user: data.info.user_id,
|
||||
customer: data.info.customer,
|
||||
});
|
||||
|
||||
const transformationService = new TransformationsService(
|
||||
this.transformationsClientService,
|
||||
|
||||
Reference in New Issue
Block a user