diff --git a/web/pages/api/v0/_types.ts b/web/pages/api/v0/_types.ts index 61f62785..47671ed4 100644 --- a/web/pages/api/v0/_types.ts +++ b/web/pages/api/v0/_types.ts @@ -43,7 +43,7 @@ export type ApiAnswer = Answer & { } export type FullMarket = LiteMarket & { - bets: Exclude[] + bets: Bet[] comments: Comment[] answers?: ApiAnswer[] } diff --git a/web/pages/api/v0/market/[id].ts b/web/pages/api/v0/market/[id].ts index 1566fed1..d9376b69 100644 --- a/web/pages/api/v0/market/[id].ts +++ b/web/pages/api/v0/market/[id].ts @@ -1,5 +1,5 @@ import { NextApiRequest, NextApiResponse } from 'next' -import { Bet, listAllBets } from 'web/lib/firebase/bets' +import { listAllBets } from 'web/lib/firebase/bets' import { listAllComments } from 'web/lib/firebase/comments' import { getContractFromId } from 'web/lib/firebase/contracts' import { applyCorsHeaders, CORS_UNRESTRICTED } from 'web/lib/api/cors' @@ -13,18 +13,12 @@ export default async function handler( const { id } = req.query const contractId = id as string - const [contract, allBets, comments] = await Promise.all([ + const [contract, bets, comments] = await Promise.all([ getContractFromId(contractId), listAllBets(contractId), listAllComments(contractId), ]) - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const bets = allBets.map(({ userId, ...bet }) => bet) as Exclude< - Bet, - 'userId' - >[] - if (!contract) { res.status(404).json({ error: 'Contract not found' }) return diff --git a/web/pages/api/v0/slug/[slug].ts b/web/pages/api/v0/slug/[slug].ts index 68913abb..b0c71171 100644 --- a/web/pages/api/v0/slug/[slug].ts +++ b/web/pages/api/v0/slug/[slug].ts @@ -1,6 +1,6 @@ import { NextApiRequest, NextApiResponse } from 'next' import { applyCorsHeaders, CORS_UNRESTRICTED } from 'web/lib/api/cors' -import { Bet, listAllBets } from 'web/lib/firebase/bets' +import { listAllBets } from 'web/lib/firebase/bets' import { listAllComments } from 'web/lib/firebase/comments' import { getContractFromSlug } from 'web/lib/firebase/contracts' import { FullMarket, ApiError, toFullMarket } from '../_types' @@ -19,17 +19,11 @@ export default async function handler( return } - const [allBets, comments] = await Promise.all([ + const [bets, comments] = await Promise.all([ listAllBets(contract.id), listAllComments(contract.id), ]) - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const bets = allBets.map(({ userId, ...bet }) => bet) as Exclude< - Bet, - 'userId' - >[] - // Cache on Vercel edge servers for 2min res.setHeader('Cache-Control', 'max-age=0, s-maxage=120') return res.status(200).json(toFullMarket(contract, comments, bets))