|
1 | 1 | import { Prisma } from '@prisma/client'
|
2 | 2 | import { prisma } from '../config/db'
|
3 |
| -import { formatResult } from '../helpers/formatter' |
4 | 3 | import { ProposalTypes, SortTypes } from '../types/proposal'
|
5 | 4 |
|
6 | 5 | export const fetchProposals = async (
|
@@ -503,7 +502,24 @@ export const fetchProposalVoteCount = async (proposalId: string, proposalIndex:
|
503 | 502 | `
|
504 | 503 | const spoSelectionQuery = Prisma.sql`SELECT 'spo' AS voterRole, (SELECT jsonb_agg(to_jsonb(poolVoteRecord)) FROM poolVoteRecord) AS voteRecord`
|
505 | 504 | const ccVoteQuery = Prisma.sql`
|
506 |
| - , committeeVoteRecord AS ( |
| 505 | + , RatifiedCommitteeGovAction AS ( |
| 506 | + SELECT gap.id |
| 507 | + FROM gov_action_proposal gap |
| 508 | + WHERE gap.type = 'NewCommittee' |
| 509 | + AND ratified_epoch IS NOT NULL |
| 510 | + ORDER BY gap.id DESC |
| 511 | + LIMIT 1 |
| 512 | + ), |
| 513 | + Committee AS ( |
| 514 | + SELECT Count(DISTINCT(ch.raw)) as committeeMembersCount |
| 515 | + FROM committee c |
| 516 | + JOIN committee_member cm ON cm.committee_id = c.id |
| 517 | + JOIN committee_hash ch ON cm.committee_hash_id = ch.id |
| 518 | + LEFT JOIN RatifiedCommitteeGovAction rc |
| 519 | + ON rc.id = c.gov_action_proposal_id |
| 520 | + WHERE c.gov_action_proposal_id IS NULL |
| 521 | + ), |
| 522 | + committeeVoteRecord AS ( |
507 | 523 | WITH CommitteeVotes AS (
|
508 | 524 | -- Count committee votes for each vote type
|
509 | 525 | SELECT
|
@@ -531,8 +547,8 @@ export const fetchProposalVoteCount = async (proposalId: string, proposalIndex:
|
531 | 547 | WHERE cm.expiration_epoch > (SELECT epoch FROM latestOrGovActionExpiration)
|
532 | 548 | ORDER BY ch.raw, cm.expiration_epoch DESC
|
533 | 549 | )
|
534 |
| - SELECT 'total_distribution' as vote_type, COUNT(DISTINCT hash) AS count |
535 |
| - FROM CommitteeData |
| 550 | + SELECT 'total_distribution' as vote_type, committeeMembersCount AS count |
| 551 | + FROM Committee |
536 | 552 | UNION ALL
|
537 | 553 | SELECT 'yes_votes' as vote_type, COALESCE(cc_Yes_Votes, 0) AS count FROM CommitteeVotes
|
538 | 554 | UNION ALL
|
@@ -1308,6 +1324,7 @@ export const fetchProposalById = async (proposalId: string, proposaIndex: number
|
1308 | 1324 | any,
|
1309 | 1325 | any
|
1310 | 1326 | >[]
|
| 1327 | + if (result.length == 0) return result |
1311 | 1328 | const proposalVoteCount = includeVoteCount
|
1312 | 1329 | ? { vote: await fetchProposalVoteCount(proposalId, proposaIndex) }
|
1313 | 1330 | : undefined
|
|
0 commit comments