mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-04-04 06:51:45 -04:00
Delete bookmarked searches in the backend
This commit is contained in:
@@ -61,6 +61,7 @@ import {vote} from "api/vote";
|
||||
import {contact} from "api/contact";
|
||||
import {saveSubscription} from "api/save-subscription";
|
||||
import {createBookmarkedSearch} from './create-bookmarked-search'
|
||||
import {deleteBookmarkedSearch} from './delete-bookmarked-search'
|
||||
|
||||
// const corsOptions: CorsOptions = {
|
||||
// origin: ['*'], // Only allow requests from this domain
|
||||
@@ -187,6 +188,7 @@ const handlers: { [k in APIPath]: APIHandler<k> } = {
|
||||
'set-last-online-time': setLastOnlineTime,
|
||||
'save-subscription': saveSubscription,
|
||||
'create-bookmarked-search': createBookmarkedSearch,
|
||||
'delete-bookmarked-search': deleteBookmarkedSearch,
|
||||
}
|
||||
|
||||
Object.entries(handlers).forEach(([path, handler]) => {
|
||||
|
||||
23
backend/api/src/delete-bookmarked-search.ts
Normal file
23
backend/api/src/delete-bookmarked-search.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import {APIHandler} from './helpers/endpoint'
|
||||
import {createSupabaseDirectClient} from 'shared/supabase/init'
|
||||
|
||||
export const deleteBookmarkedSearch: APIHandler<'delete-bookmarked-search'> = async (
|
||||
props,
|
||||
auth
|
||||
) => {
|
||||
const creator_id = auth.uid
|
||||
const {id} = props
|
||||
|
||||
const pg = createSupabaseDirectClient()
|
||||
|
||||
// Only allow deleting your own bookmarked searches
|
||||
await pg.none(
|
||||
`
|
||||
DELETE FROM bookmarked_searches
|
||||
WHERE id = $1 AND creator_id = $2
|
||||
`,
|
||||
[id, creator_id]
|
||||
)
|
||||
|
||||
return {}
|
||||
}
|
||||
@@ -595,6 +595,15 @@ export const API = (_apiTypeCheck = {
|
||||
search_name: z.string().nullable().optional(),
|
||||
}),
|
||||
},
|
||||
'delete-bookmarked-search': {
|
||||
method: 'POST',
|
||||
authed: true,
|
||||
rateLimited: true,
|
||||
returns: {} as any,
|
||||
props: z.object({
|
||||
id: z.number(),
|
||||
}),
|
||||
},
|
||||
} as const)
|
||||
|
||||
export type APIPath = keyof typeof API
|
||||
|
||||
@@ -46,9 +46,6 @@ export const deleteBookmarkedSearch = async (
|
||||
id: number,
|
||||
) => {
|
||||
if (!id) return
|
||||
await run(
|
||||
db.from('bookmarked_searches').delete().eq('id', id)
|
||||
).then(() => {
|
||||
track('bookmarked_searches delete', {id})
|
||||
})
|
||||
await api('delete-bookmarked-search', {id})
|
||||
track('bookmarked_searches delete', {id})
|
||||
}
|
||||
Reference in New Issue
Block a user