Skip to content

Commit

Permalink
Sort answers by index
Browse files Browse the repository at this point in the history
  • Loading branch information
IanPhilips committed Nov 13, 2024
1 parent 2101dc7 commit a39caa5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions backend/api/src/get-markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { convertAnswer, convertContract } from 'common/supabase/contracts'
import { contractColumnsToSelect } from 'shared/utils'
import { CPMMMultiContract } from 'common/contract'
import { APIHandler } from './helpers/endpoint'
import { sortBy } from 'lodash'

export const getMarketsByIds: APIHandler<'markets-by-ids'> = async (props) => {
const pg = createSupabaseDirectClient()
Expand All @@ -17,8 +18,9 @@ export const getMarketsByIds: APIHandler<'markets-by-ids'> = async (props) => {
const answers = results[1].map(convertAnswer)
const multiContracts = contracts.filter((c) => c.mechanism === 'cpmm-multi-1')
for (const contract of multiContracts) {
;(contract as CPMMMultiContract).answers = answers.filter(
(a) => a.contractId === contract.id
;(contract as CPMMMultiContract).answers = sortBy(
answers.filter((a) => a.contractId === contract.id),
(a) => a.index
)
}
return contracts
Expand Down

0 comments on commit a39caa5

Please sign in to comment.