mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-04-08 00:29:35 -04:00
29 lines
834 B
TypeScript
29 lines
834 B
TypeScript
import {APIError, APIHandler} from 'api/helpers/endpoint'
|
|
import {createSupabaseDirectClient} from 'shared/supabase/init'
|
|
import {log} from 'shared/utils'
|
|
import {tryCatch} from 'common/util/try-catch'
|
|
import {OPTION_TABLES} from "common/profiles/constants";
|
|
|
|
export const getOptions: APIHandler<'get-options'> = async (
|
|
{table},
|
|
_auth
|
|
) => {
|
|
if (!OPTION_TABLES.includes(table)) throw new APIError(400, 'Invalid table')
|
|
|
|
const pg = createSupabaseDirectClient()
|
|
|
|
const result = await tryCatch(
|
|
pg.manyOrNone<{ name: string }>(`SELECT interests.name
|
|
FROM interests`)
|
|
)
|
|
|
|
if (result.error) {
|
|
log('Error getting profile options', result.error)
|
|
throw new APIError(500, 'Error getting profile options')
|
|
}
|
|
|
|
const names = result.data.map(row => row.name)
|
|
return {names}
|
|
}
|
|
|