api: remove userId from bets
This commit is contained in:
parent
096a9e773a
commit
42f88766b3
|
@ -29,7 +29,7 @@ export type LiteMarket = {
|
|||
}
|
||||
|
||||
export type FullMarket = LiteMarket & {
|
||||
bets: Bet[]
|
||||
bets: Exclude<Bet, 'userId'>[]
|
||||
comments: Comment[]
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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 { getContractFromId } from '../../../../lib/firebase/contracts'
|
||||
import { FullMarket, ApiError, toLiteMarket } from '../_types'
|
||||
|
@ -11,12 +11,17 @@ export default async function handler(
|
|||
const { id } = req.query
|
||||
const contractId = id as string
|
||||
|
||||
const [contract, bets, comments] = await Promise.all([
|
||||
const [contract, allBets, comments] = await Promise.all([
|
||||
getContractFromId(contractId),
|
||||
listAllBets(contractId),
|
||||
listAllComments(contractId),
|
||||
])
|
||||
|
||||
const bets = allBets.map(({ userId, ...bet }) => bet) as Exclude<
|
||||
Bet,
|
||||
'userId'
|
||||
>[]
|
||||
|
||||
if (!contract) {
|
||||
res.status(404).json({ error: 'Contract not found' })
|
||||
return
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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 { getContractFromSlug } from '../../../../lib/firebase/contracts'
|
||||
import { FullMarket, ApiError, toLiteMarket } from '../_types'
|
||||
|
@ -17,11 +17,16 @@ export default async function handler(
|
|||
return
|
||||
}
|
||||
|
||||
const [bets, comments] = await Promise.all([
|
||||
const [allBets, comments] = await Promise.all([
|
||||
listAllBets(contract.id),
|
||||
listAllComments(contract.id),
|
||||
])
|
||||
|
||||
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({
|
||||
|
|
Loading…
Reference in New Issue
Block a user