mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-30 04:50:05 +00:00
FEAT: network config module using in-factory
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { ClientGrpc } from '@nestjs/microservices';
|
||||
import { NetworkConfig } from 'protospack-v2';
|
||||
import { lastValueFrom } from 'rxjs';
|
||||
import {
|
||||
CreateNetworkConfigReq,
|
||||
CreateNetworkConfigRes,
|
||||
DeleteNetworkConfigRes,
|
||||
FindAllNetworkConfigsRes,
|
||||
FindNetworkConfigByidRes,
|
||||
UpdateNetworkConfigReq,
|
||||
@@ -10,22 +14,54 @@ import {
|
||||
|
||||
@Injectable()
|
||||
export class NetworkConfigService {
|
||||
private networkConfigReadClient: NetworkConfig.ReadService.NetworkConfigReadService;
|
||||
private networkConfigWriteClient: NetworkConfig.WriteService.NetworkConfigWriteService;
|
||||
constructor(
|
||||
@Inject('NetworkConfigGrpcClient') private readonly grpcClient: ClientGrpc,
|
||||
) {
|
||||
this.networkConfigReadClient =
|
||||
grpcClient.getService<NetworkConfig.ReadService.NetworkConfigReadService>(
|
||||
NetworkConfig.ProtoServices.NetworkConfigReadService,
|
||||
);
|
||||
this.networkConfigWriteClient =
|
||||
grpcClient.getService<NetworkConfig.WriteService.NetworkConfigWriteService>(
|
||||
NetworkConfig.ProtoServices.NetworkConfigWriteService,
|
||||
);
|
||||
}
|
||||
async findAllNetworkConfigs(
|
||||
customer_name: string,
|
||||
): Promise<FindAllNetworkConfigsRes> {
|
||||
return { network_configs: [] };
|
||||
return lastValueFrom(
|
||||
this.networkConfigReadClient.NetworkConfigFindByCustomer({
|
||||
customer_name,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
async findNetworkConfigById(id: string): Promise<FindNetworkConfigByidRes> {
|
||||
return { network_config: undefined };
|
||||
const { network_config } = await lastValueFrom(
|
||||
this.networkConfigReadClient.NetworkConfigFindOneById({
|
||||
id,
|
||||
}),
|
||||
);
|
||||
return { network_config };
|
||||
}
|
||||
|
||||
async createNetworkConfig(
|
||||
body: CreateNetworkConfigReq,
|
||||
customer_name: string,
|
||||
): Promise<CreateNetworkConfigRes> {
|
||||
const { description, name } = body;
|
||||
return { description, id: '', name };
|
||||
const { description, name, properties, type } = body;
|
||||
const { network_config } = await lastValueFrom(
|
||||
this.networkConfigWriteClient.NetworkConfigCreate({
|
||||
customer_name,
|
||||
description,
|
||||
name,
|
||||
properties: JSON.stringify(properties),
|
||||
type,
|
||||
}),
|
||||
);
|
||||
return { network_config };
|
||||
}
|
||||
|
||||
async updateNetworkConfig(
|
||||
@@ -33,6 +69,23 @@ export class NetworkConfigService {
|
||||
network_config_id: string,
|
||||
): Promise<UpdateNetworkConfigRes> {
|
||||
const { description, name } = body;
|
||||
return { description, id: network_config_id, name };
|
||||
const { network_config } = await lastValueFrom(
|
||||
this.networkConfigWriteClient.NetworkConfigUpdate({
|
||||
id: network_config_id,
|
||||
description,
|
||||
name,
|
||||
}),
|
||||
);
|
||||
return { network_config };
|
||||
}
|
||||
|
||||
async deleteNetworkConfig(
|
||||
network_config_id: string,
|
||||
): Promise<DeleteNetworkConfigRes> {
|
||||
return lastValueFrom(
|
||||
this.networkConfigWriteClient.NetworkConfigDelete({
|
||||
id: network_config_id,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user