Add userId
to bets in API (#530)
* add userid to bets * allBets -> bets * revert one Co-authored-by: wasabipesto <21313833+wasabipesto@users.noreply.github.com>
This commit is contained in:
parent
172f14c16f
commit
732a474cc9
|
@ -43,7 +43,7 @@ export type ApiAnswer = Answer & {
|
|||
}
|
||||
|
||||
export type FullMarket = LiteMarket & {
|
||||
bets: Exclude<Bet, 'userId'>[]
|
||||
bets: Bet[]
|
||||
comments: Comment[]
|
||||
answers?: ApiAnswer[]
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue
Block a user