api: remove userId from bets

This commit is contained in:
mantikoros 2022-02-19 22:51:51 -06:00
parent 096a9e773a
commit 42f88766b3
3 changed files with 15 additions and 5 deletions

View File

@ -29,7 +29,7 @@ export type LiteMarket = {
} }
export type FullMarket = LiteMarket & { export type FullMarket = LiteMarket & {
bets: Bet[] bets: Exclude<Bet, 'userId'>[]
comments: Comment[] comments: Comment[]
} }

View File

@ -1,5 +1,5 @@
import { NextApiRequest, NextApiResponse } from 'next' import { NextApiRequest, NextApiResponse } from 'next'
import { listAllBets } from '../../../../lib/firebase/bets' import { Bet, listAllBets } from '../../../../lib/firebase/bets'
import { listAllComments } from '../../../../lib/firebase/comments' import { listAllComments } from '../../../../lib/firebase/comments'
import { getContractFromId } from '../../../../lib/firebase/contracts' import { getContractFromId } from '../../../../lib/firebase/contracts'
import { FullMarket, ApiError, toLiteMarket } from '../_types' import { FullMarket, ApiError, toLiteMarket } from '../_types'
@ -11,12 +11,17 @@ export default async function handler(
const { id } = req.query const { id } = req.query
const contractId = id as string const contractId = id as string
const [contract, bets, comments] = await Promise.all([ const [contract, allBets, comments] = await Promise.all([
getContractFromId(contractId), getContractFromId(contractId),
listAllBets(contractId), listAllBets(contractId),
listAllComments(contractId), listAllComments(contractId),
]) ])
const bets = allBets.map(({ userId, ...bet }) => bet) as Exclude<
Bet,
'userId'
>[]
if (!contract) { if (!contract) {
res.status(404).json({ error: 'Contract not found' }) res.status(404).json({ error: 'Contract not found' })
return return

View File

@ -1,5 +1,5 @@
import { NextApiRequest, NextApiResponse } from 'next' import { NextApiRequest, NextApiResponse } from 'next'
import { listAllBets } from '../../../../lib/firebase/bets' import { Bet, listAllBets } from '../../../../lib/firebase/bets'
import { listAllComments } from '../../../../lib/firebase/comments' import { listAllComments } from '../../../../lib/firebase/comments'
import { getContractFromSlug } from '../../../../lib/firebase/contracts' import { getContractFromSlug } from '../../../../lib/firebase/contracts'
import { FullMarket, ApiError, toLiteMarket } from '../_types' import { FullMarket, ApiError, toLiteMarket } from '../_types'
@ -17,11 +17,16 @@ export default async function handler(
return return
} }
const [bets, comments] = await Promise.all([ const [allBets, comments] = await Promise.all([
listAllBets(contract.id), listAllBets(contract.id),
listAllComments(contract.id), listAllComments(contract.id),
]) ])
const bets = allBets.map(({ userId, ...bet }) => bet) as Exclude<
Bet,
'userId'
>[]
// Cache on Vercel edge servers for 2min // Cache on Vercel edge servers for 2min
res.setHeader('Cache-Control', 'max-age=0, s-maxage=120') res.setHeader('Cache-Control', 'max-age=0, s-maxage=120')
return res.status(200).json({ return res.status(200).json({