-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Batch useLiveContract and include answers in api call
- Loading branch information
1 parent
5ec831b
commit 29953e0
Showing
21 changed files
with
260 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { createSupabaseDirectClient } from 'shared/supabase/init' | ||
import { convertAnswer, convertContract } from 'common/supabase/contracts' | ||
import { contractColumnsToSelect } from 'shared/utils' | ||
import { CPMMMultiContract } from 'common/contract' | ||
import { APIHandler } from './helpers/endpoint' | ||
|
||
export const getMarketsByIds: APIHandler<'markets-by-ids'> = async (props) => { | ||
const pg = createSupabaseDirectClient() | ||
const results = await pg.multi( | ||
`select ${contractColumnsToSelect} from contracts | ||
where id in ($1:list); | ||
select * from answers where contract_id in ($1:list); | ||
`, | ||
[props.ids] | ||
) | ||
const contracts = results[0].map(convertContract) | ||
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 | ||
) | ||
} | ||
return contracts | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.