Delete subset of api
This commit is contained in:
parent
f500064e4e
commit
1dc94114e3
|
@ -1,27 +0,0 @@
|
||||||
import { NextApiRequest, NextApiResponse } from 'next'
|
|
||||||
import {
|
|
||||||
CORS_ORIGIN_MANIFOLD,
|
|
||||||
CORS_ORIGIN_LOCALHOST,
|
|
||||||
} from 'common/envs/constants'
|
|
||||||
import { applyCorsHeaders } from 'web/lib/api/cors'
|
|
||||||
import { fetchBackend, forwardResponse } from 'web/lib/api/proxy'
|
|
||||||
|
|
||||||
export const config = { api: { bodyParser: true } }
|
|
||||||
|
|
||||||
export default async function route(req: NextApiRequest, res: NextApiResponse) {
|
|
||||||
await applyCorsHeaders(req, res, {
|
|
||||||
origin: [CORS_ORIGIN_MANIFOLD, CORS_ORIGIN_LOCALHOST],
|
|
||||||
methods: 'POST',
|
|
||||||
})
|
|
||||||
|
|
||||||
const { betId } = req.query as { betId: string }
|
|
||||||
|
|
||||||
if (req.body) req.body.betId = betId
|
|
||||||
try {
|
|
||||||
const backendRes = await fetchBackend(req, 'cancelbet')
|
|
||||||
await forwardResponse(res, backendRes)
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error talking to cloud function: ', err)
|
|
||||||
res.status(500).json({ message: 'Error communicating with backend.' })
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
import { NextApiRequest, NextApiResponse } from 'next'
|
|
||||||
import {
|
|
||||||
CORS_ORIGIN_MANIFOLD,
|
|
||||||
CORS_ORIGIN_LOCALHOST,
|
|
||||||
} from 'common/envs/constants'
|
|
||||||
import { applyCorsHeaders } from 'web/lib/api/cors'
|
|
||||||
import { fetchBackend, forwardResponse } from 'web/lib/api/proxy'
|
|
||||||
|
|
||||||
export const config = { api: { bodyParser: false } }
|
|
||||||
|
|
||||||
export default async function route(req: NextApiRequest, res: NextApiResponse) {
|
|
||||||
await applyCorsHeaders(req, res, {
|
|
||||||
origin: [CORS_ORIGIN_MANIFOLD, CORS_ORIGIN_LOCALHOST],
|
|
||||||
methods: 'POST',
|
|
||||||
})
|
|
||||||
try {
|
|
||||||
const backendRes = await fetchBackend(req, 'placebet')
|
|
||||||
await forwardResponse(res, backendRes)
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error talking to cloud function: ', err)
|
|
||||||
res.status(500).json({ message: 'Error communicating with backend.' })
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,66 +0,0 @@
|
||||||
import { NextApiRequest, NextApiResponse } from 'next'
|
|
||||||
import { applyCorsHeaders, CORS_UNRESTRICTED } from 'web/lib/api/cors'
|
|
||||||
import { Bet, getBets } from 'web/lib/firebase/bets'
|
|
||||||
import { getContractFromSlug } from 'web/lib/firebase/contracts'
|
|
||||||
import { getUserByUsername } from 'web/lib/firebase/users'
|
|
||||||
import { ApiError, ValidationError } from './_types'
|
|
||||||
import { z } from 'zod'
|
|
||||||
import { validate } from './_validate'
|
|
||||||
|
|
||||||
const queryParams = z
|
|
||||||
.object({
|
|
||||||
username: z.string().optional(),
|
|
||||||
market: z.string().optional(),
|
|
||||||
limit: z
|
|
||||||
.number()
|
|
||||||
.default(1000)
|
|
||||||
.or(z.string().regex(/\d+/).transform(Number))
|
|
||||||
.refine((n) => n >= 0 && n <= 1000, 'Limit must be between 0 and 1000'),
|
|
||||||
before: z.string().optional(),
|
|
||||||
})
|
|
||||||
.strict()
|
|
||||||
|
|
||||||
export default async function handler(
|
|
||||||
req: NextApiRequest,
|
|
||||||
res: NextApiResponse<Bet[] | ValidationError | ApiError>
|
|
||||||
) {
|
|
||||||
await applyCorsHeaders(req, res, CORS_UNRESTRICTED)
|
|
||||||
|
|
||||||
let params: z.infer<typeof queryParams>
|
|
||||||
try {
|
|
||||||
params = validate(queryParams, req.query)
|
|
||||||
} catch (e) {
|
|
||||||
if (e instanceof ValidationError) {
|
|
||||||
return res.status(400).json(e)
|
|
||||||
}
|
|
||||||
console.error(`Unknown error during validation: ${e}`)
|
|
||||||
return res.status(500).json({ error: 'Unknown error during validation' })
|
|
||||||
}
|
|
||||||
|
|
||||||
const { username, market, limit, before } = params
|
|
||||||
|
|
||||||
let userId: string | undefined
|
|
||||||
if (username) {
|
|
||||||
const user = await getUserByUsername(username)
|
|
||||||
if (!user) {
|
|
||||||
res.status(404).json({ error: 'User not found' })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
userId = user.id
|
|
||||||
}
|
|
||||||
|
|
||||||
let contractId: string | undefined
|
|
||||||
if (market) {
|
|
||||||
const contract = await getContractFromSlug(market)
|
|
||||||
if (!contract) {
|
|
||||||
res.status(404).json({ error: 'Contract not found' })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
contractId = contract.id
|
|
||||||
}
|
|
||||||
|
|
||||||
const bets = await getBets({ userId, contractId, limit, before })
|
|
||||||
|
|
||||||
res.setHeader('Cache-Control', 'max-age=0')
|
|
||||||
return res.status(200).json(bets)
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
import { NextApiRequest, NextApiResponse } from 'next'
|
|
||||||
import { getGroupBySlug } from 'web/lib/firebase/groups'
|
|
||||||
import { applyCorsHeaders, CORS_UNRESTRICTED } from 'web/lib/api/cors'
|
|
||||||
|
|
||||||
export default async function handler(
|
|
||||||
req: NextApiRequest,
|
|
||||||
res: NextApiResponse
|
|
||||||
) {
|
|
||||||
await applyCorsHeaders(req, res, CORS_UNRESTRICTED)
|
|
||||||
const { slug } = req.query
|
|
||||||
const group = await getGroupBySlug(slug as string)
|
|
||||||
if (!group) {
|
|
||||||
res.status(404).json({ error: 'Group not found' })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
res.setHeader('Cache-Control', 'no-cache')
|
|
||||||
return res.status(200).json(group)
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
import { NextApiRequest, NextApiResponse } from 'next'
|
|
||||||
import { getGroup } from 'web/lib/firebase/groups'
|
|
||||||
import { applyCorsHeaders, CORS_UNRESTRICTED } from 'web/lib/api/cors'
|
|
||||||
|
|
||||||
export default async function handler(
|
|
||||||
req: NextApiRequest,
|
|
||||||
res: NextApiResponse
|
|
||||||
) {
|
|
||||||
await applyCorsHeaders(req, res, CORS_UNRESTRICTED)
|
|
||||||
const { id } = req.query
|
|
||||||
const group = await getGroup(id as string)
|
|
||||||
if (!group) {
|
|
||||||
res.status(404).json({ error: 'Group not found' })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
res.setHeader('Cache-Control', 'no-cache')
|
|
||||||
return res.status(200).json(group)
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
import type { NextApiRequest, NextApiResponse } from 'next'
|
|
||||||
import { listAllGroups } from 'web/lib/firebase/groups'
|
|
||||||
import { applyCorsHeaders, CORS_UNRESTRICTED } from 'web/lib/api/cors'
|
|
||||||
|
|
||||||
type Data = any[]
|
|
||||||
|
|
||||||
export default async function handler(
|
|
||||||
req: NextApiRequest,
|
|
||||||
res: NextApiResponse<Data>
|
|
||||||
) {
|
|
||||||
await applyCorsHeaders(req, res, CORS_UNRESTRICTED)
|
|
||||||
const groups = await listAllGroups()
|
|
||||||
res.setHeader('Cache-Control', 'max-age=0')
|
|
||||||
res.status(200).json(groups)
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
import { NextApiRequest, NextApiResponse } from 'next'
|
|
||||||
import {
|
|
||||||
CORS_ORIGIN_MANIFOLD,
|
|
||||||
CORS_ORIGIN_LOCALHOST,
|
|
||||||
} from 'common/envs/constants'
|
|
||||||
import { applyCorsHeaders } from 'web/lib/api/cors'
|
|
||||||
import { fetchBackend, forwardResponse } from 'web/lib/api/proxy'
|
|
||||||
|
|
||||||
export const config = { api: { bodyParser: true } }
|
|
||||||
|
|
||||||
export default async function route(req: NextApiRequest, res: NextApiResponse) {
|
|
||||||
await applyCorsHeaders(req, res, {
|
|
||||||
origin: [CORS_ORIGIN_MANIFOLD, CORS_ORIGIN_LOCALHOST],
|
|
||||||
methods: 'POST',
|
|
||||||
})
|
|
||||||
|
|
||||||
const { id } = req.query
|
|
||||||
const contractId = id as string
|
|
||||||
|
|
||||||
if (req.body) req.body.contractId = contractId
|
|
||||||
try {
|
|
||||||
const backendRes = await fetchBackend(req, 'sellshares')
|
|
||||||
await forwardResponse(res, backendRes)
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error talking to cloud function: ', err)
|
|
||||||
res.status(500).json({ message: 'Error communicating with backend.' })
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
import { NextApiRequest, NextApiResponse } from 'next'
|
|
||||||
import { applyCorsHeaders, CORS_UNRESTRICTED } from 'web/lib/api/cors'
|
|
||||||
import { Bet, getUserBets } from 'web/lib/firebase/bets'
|
|
||||||
import { getUserByUsername } from 'web/lib/firebase/users'
|
|
||||||
import { ApiError } from '../../../_types'
|
|
||||||
|
|
||||||
export default async function handler(
|
|
||||||
req: NextApiRequest,
|
|
||||||
res: NextApiResponse<Bet[] | ApiError>
|
|
||||||
) {
|
|
||||||
await applyCorsHeaders(req, res, CORS_UNRESTRICTED)
|
|
||||||
const { username } = req.query
|
|
||||||
|
|
||||||
const user = await getUserByUsername(username as string)
|
|
||||||
|
|
||||||
if (!user) {
|
|
||||||
res.status(404).json({ error: 'User not found' })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const bets = await getUserBets(user.id, { includeRedemptions: false })
|
|
||||||
|
|
||||||
res.setHeader('Cache-Control', 'max-age=0')
|
|
||||||
return res.status(200).json(bets)
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
import { NextApiRequest, NextApiResponse } from 'next'
|
|
||||||
import { getUserByUsername } from 'web/lib/firebase/users'
|
|
||||||
import { applyCorsHeaders, CORS_UNRESTRICTED } from 'web/lib/api/cors'
|
|
||||||
import { LiteUser, ApiError, toLiteUser } from '../../_types'
|
|
||||||
|
|
||||||
export default async function handler(
|
|
||||||
req: NextApiRequest,
|
|
||||||
res: NextApiResponse<LiteUser | ApiError>
|
|
||||||
) {
|
|
||||||
await applyCorsHeaders(req, res, CORS_UNRESTRICTED)
|
|
||||||
const { username } = req.query
|
|
||||||
const user = await getUserByUsername(username as string)
|
|
||||||
if (!user) {
|
|
||||||
res.status(404).json({ error: 'User not found' })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
res.setHeader('Cache-Control', 'no-cache')
|
|
||||||
return res.status(200).json(toLiteUser(user))
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
import { NextApiRequest, NextApiResponse } from 'next'
|
|
||||||
import { getUser } from 'web/lib/firebase/users'
|
|
||||||
import { applyCorsHeaders, CORS_UNRESTRICTED } from 'web/lib/api/cors'
|
|
||||||
import { LiteUser, ApiError, toLiteUser } from '../../_types'
|
|
||||||
|
|
||||||
export default async function handler(
|
|
||||||
req: NextApiRequest,
|
|
||||||
res: NextApiResponse<LiteUser | ApiError>
|
|
||||||
) {
|
|
||||||
await applyCorsHeaders(req, res, CORS_UNRESTRICTED)
|
|
||||||
const { id } = req.query
|
|
||||||
const user = await getUser(id as string)
|
|
||||||
if (!user) {
|
|
||||||
res.status(404).json({ error: 'User not found' })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
res.setHeader('Cache-Control', 'no-cache')
|
|
||||||
return res.status(200).json(toLiteUser(user))
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
// Next.js API route support: https://vercel.com/docs/concepts/functions/serverless-functions
|
|
||||||
import type { NextApiRequest, NextApiResponse } from 'next'
|
|
||||||
import { listAllUsers } from 'web/lib/firebase/users'
|
|
||||||
import { applyCorsHeaders, CORS_UNRESTRICTED } from 'web/lib/api/cors'
|
|
||||||
import { toLiteUser } from './_types'
|
|
||||||
|
|
||||||
type Data = any[]
|
|
||||||
|
|
||||||
export default async function handler(
|
|
||||||
req: NextApiRequest,
|
|
||||||
res: NextApiResponse<Data>
|
|
||||||
) {
|
|
||||||
await applyCorsHeaders(req, res, CORS_UNRESTRICTED)
|
|
||||||
const users = await listAllUsers()
|
|
||||||
res.setHeader('Cache-Control', 'max-age=0')
|
|
||||||
res.status(200).json(users.map(toLiteUser))
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user