mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-03-26 10:31:10 -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
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import {FilterFields} from 'common/filters'
|
|
import {Row, run} from 'common/supabase/utils'
|
|
import {removeNullOrUndefinedProps} from 'common/util/object'
|
|
import {filterKeys} from 'web/components/questions-form'
|
|
import {api} from 'web/lib/api'
|
|
import {track} from 'web/lib/service/analytics'
|
|
import {db} from 'web/lib/supabase/db'
|
|
|
|
export const getUserBookmarkedSearches = async (userId: string) => {
|
|
const {data} = await run(
|
|
db
|
|
.from('bookmarked_searches')
|
|
.select('*')
|
|
.eq('creator_id', userId)
|
|
.order('id', {ascending: false}),
|
|
)
|
|
return data
|
|
}
|
|
|
|
export type BookmarkedSearchSubmitType = Omit<
|
|
Row<'bookmarked_searches'>,
|
|
'created_time' | 'id' | 'last_notified_at' | 'creator_id'
|
|
>
|
|
|
|
export const submitBookmarkedSearch = async (
|
|
filters: Partial<FilterFields>,
|
|
locationFilterProps: any,
|
|
userId: string | undefined | null,
|
|
) => {
|
|
if (!filters) return
|
|
if (!userId) return
|
|
|
|
const row = {
|
|
search_filters: removeNullOrUndefinedProps(filters),
|
|
location: locationFilterProps?.location ? locationFilterProps : null,
|
|
}
|
|
const props = {
|
|
...filterKeys(
|
|
row,
|
|
(key, _) => !['id', 'created_time', 'last_notified_at', 'creator_id'].includes(key),
|
|
),
|
|
} as BookmarkedSearchSubmitType
|
|
|
|
await api('create-bookmarked-search', props)
|
|
}
|
|
|
|
export const deleteBookmarkedSearch = async (id: number) => {
|
|
if (!id) return
|
|
await api('delete-bookmarked-search', {id})
|
|
track('bookmarked_searches delete', {id})
|
|
}
|