Skip to content

Commit 89bd831

Browse files
authored
Merge pull request #9 from cardanoapi/enhancement/proposal-API
Enhancement: Proposal API
2 parents 295996e + c593d3e commit 89bd831

File tree

3 files changed

+28
-17
lines changed

3 files changed

+28
-17
lines changed

src/controllers/proposal.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ const router = Router()
99
const getProposals = async (req: Request, res: Response) => {
1010
const size = req.query.size ? +req.query.size : 10
1111
const page = req.query.page ? +req.query.page : 1
12-
const type = req.query.type ? (req.query.type as ProposalTypes) : undefined
12+
const type = req.query.type
13+
? Array.isArray(req.query.type)
14+
? (req.query.type as ProposalTypes[])
15+
: typeof req.query.type === 'string'
16+
? req.query.type.split(',').map((type) => type as ProposalTypes)
17+
: undefined
18+
: undefined
1319
const sort = req.query.sort ? (req.query.sort as SortTypes) : undefined
1420
const includeVoteCount = 'true' == (req.query.vote_count as string)
1521
let proposal = req.query.proposal as string
@@ -21,7 +27,7 @@ const getProposals = async (req: Request, res: Response) => {
2127
proposal = proposal.includes('#') ? proposal.split('#')[0] : proposal
2228
}
2329
const { items, totalCount } = await fetchProposals(page, size, proposal, type, sort, includeVoteCount)
24-
return res.status(200).json({ totalCount: Math.round(totalCount / size), page, size, items })
30+
return res.status(200).json({ totalCount: totalCount, page, size, items })
2531
}
2632

2733
const getProposalVoteCount = async (req: Request, res: Response) => {

src/repository/proposal.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const fetchProposals = async (
66
page: number,
77
size: number,
88
proposal?: string,
9-
proposalType?: ProposalTypes,
9+
proposalType?: ProposalTypes[],
1010
sort?: SortTypes,
1111
includeVoteCount?: boolean
1212
) => {
@@ -292,10 +292,13 @@ FROM
292292
AND gov_action_proposal.dropped_epoch IS NULL
293293
${
294294
proposalType
295-
? Prisma.sql`Where gov_action_proposal.type = ${Prisma.raw(`'${proposalType}'::govactiontype`)}`
295+
? Prisma.sql`WHERE gov_action_proposal.type = ANY(${Prisma.raw(
296+
`ARRAY[${proposalType.map((type) => `'${type}'`).join(', ')}]::govactiontype[]`
297+
)})`
296298
: Prisma.sql``
297-
}
298-
GROUP BY
299+
}
300+
301+
GROUP BY
299302
(gov_action_proposal.id,
300303
stake_address.view,
301304
treasury_withdrawal.amount,

swagger.yaml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -850,17 +850,19 @@ paths:
850850
- in: query
851851
name: type
852852
schema:
853-
type: string
854-
enum:
855-
[
856-
ParameterChange,
857-
HardForkInitiation,
858-
TreasuryWithdrawals,
859-
NoConfidence,
860-
NewCommittee,
861-
NewConstitution,
862-
InfoAction,
863-
]
853+
type: array
854+
items:
855+
type: string
856+
enum:
857+
- ParameterChange
858+
- HardForkInitiation
859+
- TreasuryWithdrawals
860+
- NoConfidence
861+
- NewCommittee
862+
- NewConstitution
863+
- InfoAction
864+
description: Filter by one or more action types.
865+
explode: true
864866
- in: query
865867
name: proposal
866868
description: Search by proposal id

0 commit comments

Comments
 (0)