forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgovernance.controller.ts
More file actions
114 lines (104 loc) · 2.75 KB
/
Copy pathgovernance.controller.ts
File metadata and controls
114 lines (104 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import {
Controller,
Get,
Post,
Body,
Param,
Query,
HttpCode,
HttpStatus,
} from '@nestjs/common';
import { GovernanceService } from './governance.service';
import { CreateProposalDto } from './dto/create-proposal.dto';
import { CastVoteDto, CastVoteWithTypeDto } from './dto/vote.dto';
import { ExecuteProposalDto, VetoProposalDto } from './dto/execute-proposal.dto';
import { ProposalStatus } from './entities/proposal.entity';
@Controller('governance')
export class GovernanceController {
constructor(private readonly governanceService: GovernanceService) {}
@Post('proposals')
@HttpCode(HttpStatus.CREATED)
async createProposal(@Body() dto: CreateProposalDto) {
const proposal = await this.governanceService.createProposal(dto);
return {
success: true,
data: {
proposalId: proposal.id,
proposal,
},
};
}
@Get('proposals')
async getProposals(@Query('status') status?: ProposalStatus) {
const proposals = await this.governanceService.getProposals(status);
return {
success: true,
data: proposals,
};
}
@Get('proposals/:id')
async getProposal(@Param('id') id: string) {
const proposal = await this.governanceService.getProposal(id);
return {
success: true,
data: proposal,
};
}
@Post('vote')
@HttpCode(HttpStatus.OK)
async vote(@Body() dto: CastVoteDto) {
await this.governanceService.vote(dto);
return {
success: true,
message: 'Vote cast successfully',
};
}
@Post('vote-with-type')
@HttpCode(HttpStatus.OK)
async voteWithType(@Body() dto: CastVoteWithTypeDto) {
await this.governanceService.voteWithType(dto);
return {
success: true,
message: 'Vote cast successfully',
};
}
@Get('proposals/:id/votes')
async getVotes(@Param('id') id: string) {
const votes = await this.governanceService.getVotes(id);
return {
success: true,
data: votes,
};
}
@Post('execute')
@HttpCode(HttpStatus.OK)
async executeProposal(@Body() dto: ExecuteProposalDto) {
await this.governanceService.executeProposal(dto.proposalId);
return {
success: true,
message: 'Proposal executed successfully',
};
}
@Post('veto')
@HttpCode(HttpStatus.OK)
async vetoProposal(@Body() dto: VetoProposalDto) {
await this.governanceService.vetoProposal(
dto.proposalId,
dto.vetoer,
dto.reason,
);
return {
success: true,
message: 'Proposal vetoed successfully',
};
}
@Post('proposals/:id/finalize')
@HttpCode(HttpStatus.OK)
async finalizeProposal(@Param('id') id: string) {
await this.governanceService.finalizeProposal(id);
return {
success: true,
message: 'Proposal finalized successfully',
};
}
}