@@ -29,38 +29,29 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
2929const handleGetAll = async ( req : NextApiRequest , res : NextApiResponse ) => {
3030 const headers = constructHeaders ( req . headers )
3131
32- const onlyAuthSchema = req . query [ 'schema' ] === 'auth'
33- const onlyStorageSchema = req . query [ 'schema' ] === 'storage'
34-
35- const includeAuthSchema = true // req.query['auth-schema'] === 'true'
36- const includeStorageSchema = true // req.query['storage-schema'] === 'true'
32+ const query = Object . entries ( req . query ) . reduce ( ( query , entry ) => {
33+ const [ key , value ] = entry
34+ if ( Array . isArray ( value ) ) {
35+ for ( const v of value ) {
36+ query . append ( key , v )
37+ }
38+ } else if ( value ) {
39+ query . set ( key , value )
40+ }
41+ return query
42+ } , new URLSearchParams ( ) )
43+
44+ let url = `${ PG_META_URL } /tables`
45+ if ( Object . keys ( req . query ) . length > 0 ) {
46+ url += `?${ query } `
47+ }
3748
38- const response = await get ( ` ${ PG_META_URL } /tables` , { headers } )
49+ const response = await get ( url , { headers } )
3950 if ( response . error ) {
4051 return res . status ( 400 ) . json ( { error : response . error } )
4152 }
4253
43- let tables = response || [ ]
44-
45- if ( onlyStorageSchema ) {
46- const storageTables = tables ?. filter ( ( x : any ) => x . schema === 'storage' )
47- return res . status ( 200 ) . json ( storageTables )
48- }
49-
50- if ( onlyAuthSchema ) {
51- const authTables = tables ?. filter ( ( x : any ) => x . schema === 'auth' )
52- return res . status ( 200 ) . json ( authTables )
53- }
54-
55- if ( ! includeAuthSchema && Array . isArray ( tables ) ) {
56- tables = tables ?. filter ( ( x ) => x . schema !== 'auth' )
57- }
58-
59- if ( ! includeStorageSchema && Array . isArray ( tables ) ) {
60- tables = tables ?. filter ( ( x ) => x . schema !== 'storage' )
61- }
62-
63- return res . status ( 200 ) . json ( tables )
54+ return res . status ( 200 ) . json ( response )
6455}
6556
6657const handleGetOne = async ( req : NextApiRequest , res : NextApiResponse ) => {
0 commit comments