mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-03-25 10:02:27 -04:00
* Test * Add pretty formatting * Fix Tests * Fix Tests * Fix Tests * Fix * Add pretty formatting fix * Fix * Test * Fix tests * Clean typeckech * Add prettier check * Fix api tsconfig * Fix api tsconfig * Fix tsconfig * Fix * Fix * Prettier
25 lines
827 B
TypeScript
25 lines
827 B
TypeScript
import {APIError, APIHandler} from 'api/helpers/endpoint'
|
|
import {OPTION_TABLES} from 'common/profiles/constants'
|
|
import {tryCatch} from 'common/util/try-catch'
|
|
import {createSupabaseDirectClient} from 'shared/supabase/init'
|
|
import {log} from 'shared/utils'
|
|
|
|
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}
|
|
}
|