mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-23 01:19:08 +00:00
maestro connection with microservices - clients and modules
This commit is contained in:
@@ -1,65 +1,159 @@
|
||||
// import {
|
||||
// Controller,
|
||||
// Delete,
|
||||
// Get,
|
||||
// OnModuleInit,
|
||||
// Param,
|
||||
// Post,
|
||||
// Put,
|
||||
// } from '@nestjs/common';
|
||||
// import {
|
||||
// Client,
|
||||
// ClientGrpc,
|
||||
// MessagePattern,
|
||||
// Payload,
|
||||
// } from '@nestjs/microservices';
|
||||
// import { TransformationsService } from './transformations.service';
|
||||
// import { CreateTransformationDto } from './dto/create-transformation.dto';
|
||||
// import { UpdateTransformationDto } from './dto/update-transformation.dto';
|
||||
// import { ApiTags } from '@nestjs/swagger';
|
||||
// import { GrpcClientConfiguration } from './client.config';
|
||||
import {
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
Inject,
|
||||
OnModuleInit,
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
} from '@nestjs/common';
|
||||
import {
|
||||
Client,
|
||||
ClientGrpc,
|
||||
MessagePattern,
|
||||
Payload,
|
||||
} from '@nestjs/microservices';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { TransformationsServiceInterface } from '@victorradael/protospack';
|
||||
import { ICreateTransformationElement, ICreateTransformationsRequest, IdRequest, IUpdateTransformationRequest } from './interfaces';
|
||||
|
||||
// @Controller('transformation')
|
||||
// export class TransformationsClientService implements OnModuleInit {
|
||||
// @Client(GrpcClientConfiguration)
|
||||
// private transformationServiceClient: ClientGrpc;
|
||||
@Controller('transformation')
|
||||
export class TransformationsClientService implements OnModuleInit {
|
||||
private transformationService: TransformationsServiceInterface;
|
||||
constructor(
|
||||
@Inject('TRANSFORMATIONS_PACKAGE') private readonly grpcClient: ClientGrpc,
|
||||
) {}
|
||||
|
||||
// private transformationService: TransformationsService;
|
||||
onModuleInit() {
|
||||
this.transformationService =
|
||||
this.grpcClient.getService<TransformationsServiceInterface>(
|
||||
'TransformationService',
|
||||
);
|
||||
}
|
||||
|
||||
// onModuleInit() {
|
||||
// this.transformationService =
|
||||
// this.transformationServiceClient.getService<TransformationsService>(
|
||||
// 'TransformationService',
|
||||
// );
|
||||
// }
|
||||
@Post()
|
||||
async create(createTransformationsDto: ICreateTransformationsRequest) {
|
||||
console.log('TransformationClientService', 'Create');
|
||||
|
||||
// @Post()
|
||||
// create(@Payload() createTransformationDto: CreateTransformationDto[]) {
|
||||
// return createTransformationDto.map((transf) =>
|
||||
// this.transformationService.create(transf),
|
||||
// );
|
||||
// }
|
||||
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');
|
||||
},
|
||||
});
|
||||
})
|
||||
.then((res) => res)
|
||||
.catch((err) => {
|
||||
throw new Error(err);
|
||||
});
|
||||
return createTransformationResponse;
|
||||
}
|
||||
|
||||
// @Get()
|
||||
// list() {
|
||||
// return this.transformationService.list();
|
||||
// }
|
||||
async findAll() {
|
||||
console.log('TransformationClientService', 'FindAll');
|
||||
|
||||
// @Get(':id')
|
||||
// show(@Payload() id: string) {
|
||||
// return this.transformationService.show(id);
|
||||
// }
|
||||
const findAllTransformationResponse = await new Promise((resolve, reject) => {
|
||||
this.transformationService.findAll({}).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
error(err) {
|
||||
console.log('Observable Error');
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
console.log('done');
|
||||
},
|
||||
});
|
||||
})
|
||||
.then((res) => res)
|
||||
.catch((err) => {
|
||||
throw new Error(err);
|
||||
});
|
||||
|
||||
// @Put(':id')
|
||||
// update(
|
||||
// @Param() id: string,
|
||||
// @Payload() updateTransformationDto: UpdateTransformationDto,
|
||||
// ) {
|
||||
// return this.transformationService.update(id, updateTransformationDto);
|
||||
// }
|
||||
return findAllTransformationResponse;
|
||||
}
|
||||
|
||||
// @Delete(':id')
|
||||
// remove(@Param() id: string) {
|
||||
// return this.transformationService.remove(id);
|
||||
// }
|
||||
// }
|
||||
async findOne({id}: IdRequest) {
|
||||
console.log('TransformationClientService', 'FindOne');
|
||||
|
||||
const findOneTransformationResponse = await new Promise((resolve, reject) => {
|
||||
this.transformationService.findOne({id}).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
error(err) {
|
||||
console.log('Observable Error');
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
console.log('done');
|
||||
},
|
||||
});
|
||||
})
|
||||
.then((res) => res)
|
||||
.catch((err) => {
|
||||
throw new Error(err);
|
||||
});
|
||||
|
||||
return findOneTransformationResponse;
|
||||
}
|
||||
|
||||
async update(updateTransformationDTO: IUpdateTransformationRequest) {
|
||||
console.log('TransformationClientService', 'Update');
|
||||
|
||||
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');
|
||||
},
|
||||
});
|
||||
})
|
||||
.then((res) => res)
|
||||
.catch((err) => {
|
||||
throw new Error(err);
|
||||
});
|
||||
|
||||
return updateTransformationResponse;
|
||||
}
|
||||
|
||||
async remove({id}: IdRequest) {
|
||||
console.log('TransformationClientService', 'Remove');
|
||||
|
||||
const removeTransformationResponse = await new Promise((resolve, reject) => {
|
||||
this.transformationService.remove({id}).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
error(err) {
|
||||
console.log('Observable Error');
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
console.log('done');
|
||||
},
|
||||
});
|
||||
})
|
||||
.then((res) => res)
|
||||
.catch((err) => {
|
||||
throw new Error(err);
|
||||
});
|
||||
|
||||
return removeTransformationResponse;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user