Skip to content

Commit

Permalink
fix: failed dissolve network(#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
dayuy authored and Carrotzpc committed Apr 18, 2023
1 parent 3eb0957 commit ed20a72
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/network/network.gql
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ mutation createNetwork($network: NewNetworkInput!) {
}

# 释放网络
mutation dissolveNetwork($name: String!, $federation: String!, $initiator: String!) {
networkDissolve(name: $name, federation: $federation, initiator: $initiator)
mutation dissolveNetwork($name: String!, $federation: String!) {
networkDissolve(name: $name, federation: $federation)
}

# 删除网络
Expand Down
8 changes: 1 addition & 7 deletions src/network/network.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,8 @@ export class NetworkResolver {
@Auth() auth: JwtAuth,
@Args('name') name: string,
@Args('federation', { description: '所属联盟' }) federation: string,
@Args('initiator', { description: '网络发起者(组织)' }) initiator: string,
): Promise<boolean> {
return this.networkService.dissolveNetwork(
auth,
name,
federation,
initiator,
);
return this.networkService.dissolveNetwork(auth, name, federation);
}

@Mutation(() => K8sV1Status, { description: '删除网络' })
Expand Down
25 changes: 22 additions & 3 deletions src/network/network.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { forwardRef, Inject, Injectable, Logger } from '@nestjs/common';
import {
forwardRef,
Inject,
Injectable,
InternalServerErrorException,
Logger,
} from '@nestjs/common';
import { ConfigType } from '@nestjs/config';
import { compact, uniq } from 'lodash';
import { ChaincodeService } from 'src/chaincode/chaincode.service';
Expand Down Expand Up @@ -177,15 +183,28 @@ export class NetworkService {
auth: JwtAuth,
name: string,
federation: string,
initiator: string,
): Promise<boolean> {
// 0. 当前用户的组织作为发起者
const { preferred_username } = auth;
const orgs = await this.orgService.getOrganizations(auth);
const initiator = orgs.find(
(org) =>
(org?.admin === preferred_username ||
org?.clients?.includes(preferred_username)) &&
org.federations?.includes(federation),
);

if (!initiator) {
throw new InternalServerErrorException('The initiator is invalid.');
}

// 1. 发起提案
await this.proposalService.createProposal(
auth,
ProposalType.DissolveNetworkProposal,
{
federation,
initiator,
initiator: initiator?.name,
network: name,
},
);
Expand Down
3 changes: 0 additions & 3 deletions src/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,6 @@ type Mutation {
networkDissolve(
"""所属联盟"""
federation: String!

"""网络发起者(组织)"""
initiator: String!
name: String!
): Boolean!

Expand Down

0 comments on commit ed20a72

Please sign in to comment.