Skip to content

Commit

Permalink
fix: add optional values of crdStatusType(#41) (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
dayuy authored Mar 6, 2023
1 parent bd9a312 commit 68b7258
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 164 deletions.
7 changes: 4 additions & 3 deletions src/channel/channel.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ export class ChannelService {
): Promise<Channel> {
const { name, description, initiator, organizations, peers, policy } =
channel;
const members = (organizations || [])
.concat(initiator)
.map((d) => ({ name: d, initiator: d === initiator }));
const members = uniq((organizations || []).concat(initiator)).map((d) => ({
name: d,
initiator: d === initiator,
}));
const k8s = await this.k8sService.getClient(auth);
const { body } = await k8s.channel.create({
metadata: {
Expand Down
4 changes: 2 additions & 2 deletions src/channel/models/channel.model.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Field, ID, ObjectType } from '@nestjs/graphql';
import { CrdStatusType } from 'src/common/models/crd-statue-type.enum';
import { SpecMember } from 'src/common/models/spec-member.model';
import { Epolicy } from 'src/epolicy/models/epolicy.model';
import { ChannelStatus } from './channel-status.enum';
import { SpecPeer } from './spec-peer.model';

@ObjectType()
Expand All @@ -25,7 +25,7 @@ export class Channel {
creationTimestamp?: string;

/** 状态 */
@Field(() => ChannelStatus, { description: '状态' })
@Field(() => CrdStatusType, { description: '状态' })
status?: string;

/** 我创建的 */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { registerEnumType } from '@nestjs/graphql';

export enum StatusType {
export enum CrdStatusType {
Deploying = 'Deploying',
Deployed = 'Deployed',
Precreated = 'Precreated',
Expand All @@ -14,10 +14,12 @@ export enum StatusType {
FederationDissolved = 'FederationDissolved',
NetworkCreated = 'NetworkCreated',
NetworkDissolved = 'NetworkDissolved',
ChannelCreated = 'ChannelCreated',
ChannelArchived = 'ChannelArchived',
}

registerEnumType(StatusType, {
name: 'StatusType',
registerEnumType(CrdStatusType, {
name: 'CrdStatusType',
description: 'IBPCR 状态',
valuesMap: {
Deploying: {
Expand Down Expand Up @@ -46,22 +48,28 @@ registerEnumType(StatusType, {
description: '正常',
},
FederationPending: {
description: 'FederationPending means `Proposal-Vote` not passed yet',
description: '组建中',
},
FederationActivated: {
description: 'FederationActivated means `Proposal-Vote` passed',
description: '已激活',
},
FederationFailed: {
description: 'FederationFailed means `Proposal-Vote` failed',
description: '组建失败',
},
FederationDissolved: {
description: 'FederationDissolved means `Federation` no longer active',
description: '已解散',
},
NetworkCreated: {
description: '正常',
},
NetworkDissolved: {
description: '已解散',
},
ChannelCreated: {
description: 'ChannelCreated',
},
ChannelArchived: {
description: 'ChannelArchived',
},
},
});
4 changes: 2 additions & 2 deletions src/federation/federation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import { CRD } from 'src/kubernetes/lib';
import { NewFederationInput } from './dto/new-federation.input';
import { ProposalService } from 'src/proposal/proposal.service';
import { ProposalType } from 'src/proposal/models/proposal-type.enum';
import { FederationStatus } from './models/federation-status.enum';
import { K8sV1Status } from 'src/common/models/k8s-v1-status.model';
import { OrganizationService } from 'src/organization/organization.service';
import { uniq } from 'lodash';
import { CrdStatusType } from 'src/common/models/crd-statue-type.enum';

@Injectable()
export class FederationService {
Expand Down Expand Up @@ -200,7 +200,7 @@ export class FederationService {

async deleteFederation(auth: JwtAuth, name: string): Promise<K8sV1Status> {
const detail = await this.federation(auth, name);
if (detail?.status !== FederationStatus.FederationDissolved) {
if (detail?.status !== CrdStatusType.FederationDissolved) {
throw new InternalServerErrorException(
'Only dissolved federation can be deleted.',
);
Expand Down
31 changes: 0 additions & 31 deletions src/federation/models/federation-status.enum.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/federation/models/federation.model.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ObjectType, Field, ID, HideField } from '@nestjs/graphql';
import { CrdStatusType } from 'src/common/models/crd-statue-type.enum';
import { SpecMember } from 'src/common/models/spec-member.model';
import { Network } from 'src/network/models/network.model';
import { Organization } from 'src/organization/models/organization.model';
import { ProposalPolicy } from 'src/proposal/models/proposal-policy.enum';
import { FederationStatus } from './federation-status.enum';

@ObjectType({ description: '联盟' })
export class Federation {
Expand Down Expand Up @@ -42,6 +42,6 @@ export class Federation {
policy?: string;

/** 状态 */
@Field(() => FederationStatus, { description: '状态' })
@Field(() => CrdStatusType, { description: '状态' })
status?: string;
}
23 changes: 0 additions & 23 deletions src/ibppeer/models/ibppeer-status.enum.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/ibppeer/models/ibppeer.model.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Field, HideField, ID, ObjectType } from '@nestjs/graphql';
import { CrdStatusType } from 'src/common/models/crd-statue-type.enum';
import { SpecResource } from 'src/common/models/spec-resource.model';
import { AnyObj } from 'src/types';
import { IbppeerStatus } from './ibppeer-status.enum';

@ObjectType()
export class Ibppeer {
Expand All @@ -25,7 +25,7 @@ export class Ibppeer {
limits?: AnyObj;

/** 运行状态 */
@Field(() => IbppeerStatus, { description: '运行状态' })
@Field(() => CrdStatusType, { description: '运行状态' })
status?: string;

@HideField()
Expand Down
4 changes: 2 additions & 2 deletions src/network/models/network.model.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Field, HideField, ID, ObjectType } from '@nestjs/graphql';
import { Channel } from 'src/channel/models/channel.model';
import { CrdStatusType } from 'src/common/models/crd-statue-type.enum';
import { SpecResource } from 'src/common/models/spec-resource.model';
import { Ibppeer } from 'src/ibppeer/models/ibppeer.model';
import { Organization } from 'src/organization/models/organization.model';
import { StatusType } from 'src/organization/models/status-type.enum';
import { AnyObj } from 'src/types';
import { OrderVersion } from '../dto/order-version.enum';

Expand All @@ -25,7 +25,7 @@ export class Network {
expiredTime?: string;

/** 状态 */
@Field(() => StatusType, { description: '状态' })
@Field(() => CrdStatusType, { description: '状态' })
status?: string;

/** 引擎类型 */
Expand Down
4 changes: 2 additions & 2 deletions src/organization/models/organization.model.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Field, HideField, ID, ObjectType } from '@nestjs/graphql';
import { CrdStatusType } from 'src/common/models/crd-statue-type.enum';
import { Ibppeer } from 'src/ibppeer/models/ibppeer.model';
import { Network } from 'src/network/models/network.model';
import { User } from 'src/users/models/user.model';
import { StatusType } from './status-type.enum';

@ObjectType({ description: '组织' })
export class Organization {
Expand Down Expand Up @@ -32,7 +32,7 @@ export class Organization {
clients?: string[];

/** 状态 */
@Field(() => StatusType)
@Field(() => CrdStatusType)
status?: string;

/** 原因 */
Expand Down
Loading

0 comments on commit 68b7258

Please sign in to comment.