mirror of
https://github.com/supabase/supabase.git
synced 2026-10-17 15:19:08 +03:00
* fix: only list views, foreign tables, material views in selected schema * fix(studio): views filterings on local studio experience --------- Co-authored-by: jingsam <jing-sam@qq.com>
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
import { NextApiRequest, NextApiResponse } from 'next'
|
|
|
|
import apiWrapper from 'lib/api/apiWrapper'
|
|
import { get } from 'lib/common/fetch'
|
|
import { constructHeaders } from 'lib/api/apiHelpers'
|
|
import { PG_META_URL } from 'lib/constants'
|
|
import { getPgMetaRedirectUrl } from './tables'
|
|
|
|
export default (req: NextApiRequest, res: NextApiResponse) =>
|
|
apiWrapper(req, res, handler, { withAuth: true })
|
|
|
|
async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|
const { method } = req
|
|
|
|
switch (method) {
|
|
case 'GET':
|
|
if (req.query.id) return handleGetOne(req, res)
|
|
return handleGetAll(req, res)
|
|
default:
|
|
res.setHeader('Allow', ['GET'])
|
|
res.status(405).json({ error: { message: `Method ${method} Not Allowed` } })
|
|
}
|
|
}
|
|
|
|
const handleGetAll = async (req: NextApiRequest, res: NextApiResponse) => {
|
|
const headers = constructHeaders(req.headers)
|
|
let response = await get(getPgMetaRedirectUrl(req, 'views'), {
|
|
headers,
|
|
})
|
|
if (response.error) {
|
|
return res.status(400).json({ error: response.error })
|
|
}
|
|
|
|
return res.status(200).json(response)
|
|
}
|
|
|
|
const handleGetOne = async (req: NextApiRequest, res: NextApiResponse) => {
|
|
const headers = constructHeaders(req.headers)
|
|
let response = await get(`${PG_META_URL}/views/${req.query.id}`, {
|
|
headers,
|
|
})
|
|
if (response.error) {
|
|
return res.status(400).json({ error: response.error })
|
|
}
|
|
return res.status(200).json(response)
|
|
}
|