Skip to content

Commit

Permalink
Merge pull request #1131 from multiversx/MEX-348
Browse files Browse the repository at this point in the history
MEX-348: governance description fixes
  • Loading branch information
dragos-rebegea authored Aug 7, 2023
2 parents 7e982a0 + 497d5b0 commit 2a56004
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
10 changes: 4 additions & 6 deletions src/modules/governance/models/governance.proposal.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,25 @@ export enum VoteType {
registerEnumType(GovernanceProposalStatus, { name: 'VoteType' });

@ObjectType()
export class Description_v0 {
export class DescriptionV0 {
@Field()
title: string;
@Field()
hash: string;
@Field(() => Int)
strapiId: number;
@Field()
version: number;

constructor(init: Partial<Description_v0>) {
constructor(init: Partial<DescriptionV0>) {
Object.assign(this, init);
}
}

@ObjectType()
export class Description_v1 extends Description_v0 {
export class DescriptionV1 extends DescriptionV0 {
@Field()
shortDescription: string;

constructor(init: Partial<Description_v1>) {
constructor(init: Partial<DescriptionV1>) {
super(init);
Object.assign(this, init);
}
Expand Down
10 changes: 5 additions & 5 deletions src/modules/governance/models/governance.union.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createUnionType } from '@nestjs/graphql';
import { GovernanceEnergyContract, GovernanceTokenSnapshotContract } from './governance.contract.model';
import { Description_v0, Description_v1 } from './governance.proposal.model';
import { DescriptionV0, DescriptionV1 } from './governance.proposal.model';

export const GovernanceUnion = createUnionType({
name: 'GovernanceTypes',
Expand All @@ -23,15 +23,15 @@ export const GovernanceDescriptionUnion = createUnionType({
name: 'GovernanceDescriptionVersions',
types: () =>
[
Description_v0,
Description_v1,
DescriptionV0,
DescriptionV1,
] as const,
resolveType(description) {
switch (description.version) {
case 0:
return Description_v0;
return DescriptionV0;
case 1:
return Description_v1;
return DescriptionV1;
}
},
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { GovernanceDescriptionUnion } from '../models/governance.union';
import { Description_v0, Description_v1 } from '../models/governance.proposal.model';
import { DescriptionV0, DescriptionV1 } from '../models/governance.proposal.model';


@Injectable()
Expand All @@ -9,9 +9,9 @@ export class GovernanceDescriptionService {
const description = JSON.parse(descriptionJson);
switch (description.version) {
case 0:
return new Description_v0(description);
return new DescriptionV0(description);
case 1:
return new Description_v1(description);
return new DescriptionV1(description);
default:
throw new Error(`Unknown description version: ${description.version}`);
}
Expand Down

0 comments on commit 2a56004

Please sign in to comment.