mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-19 03:49:08 +00:00
92 lines
2.7 KiB
TypeScript
92 lines
2.7 KiB
TypeScript
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,
|
|
UpdateNetworkConfigRes,
|
|
} from './dto/network-config';
|
|
|
|
@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 lastValueFrom(
|
|
this.networkConfigReadClient.NetworkConfigFindByCustomer({
|
|
customer_name,
|
|
}),
|
|
);
|
|
}
|
|
|
|
async findNetworkConfigById(id: string): Promise<FindNetworkConfigByidRes> {
|
|
const { network_config } = await lastValueFrom(
|
|
this.networkConfigReadClient.NetworkConfigFindOneById({
|
|
id,
|
|
}),
|
|
);
|
|
return { network_config };
|
|
}
|
|
|
|
async createNetworkConfig(
|
|
body: CreateNetworkConfigReq,
|
|
customer_name: string,
|
|
): Promise<CreateNetworkConfigRes> {
|
|
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(
|
|
body: UpdateNetworkConfigReq,
|
|
network_config_id: string,
|
|
): Promise<UpdateNetworkConfigRes> {
|
|
const { description, name } = body;
|
|
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,
|
|
}),
|
|
);
|
|
}
|
|
}
|