File tree Expand file tree Collapse file tree 4 files changed +36
-5
lines changed
Expand file tree Collapse file tree 4 files changed +36
-5
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,7 @@ import {vote} from "api/vote";
6161import { contact } from "api/contact" ;
6262import { saveSubscription } from "api/save-subscription" ;
6363import { createBookmarkedSearch } from './create-bookmarked-search'
64+ import { deleteBookmarkedSearch } from './delete-bookmarked-search'
6465
6566// const corsOptions: CorsOptions = {
6667// origin: ['*'], // Only allow requests from this domain
@@ -187,6 +188,7 @@ const handlers: { [k in APIPath]: APIHandler<k> } = {
187188 'set-last-online-time' : setLastOnlineTime ,
188189 'save-subscription' : saveSubscription ,
189190 'create-bookmarked-search' : createBookmarkedSearch ,
191+ 'delete-bookmarked-search' : deleteBookmarkedSearch ,
190192}
191193
192194Object . entries ( handlers ) . forEach ( ( [ path , handler ] ) => {
Original file line number Diff line number Diff line change 1+ import { APIHandler } from './helpers/endpoint'
2+ import { createSupabaseDirectClient } from 'shared/supabase/init'
3+
4+ export const deleteBookmarkedSearch : APIHandler < 'delete-bookmarked-search' > = async (
5+ props ,
6+ auth
7+ ) => {
8+ const creator_id = auth . uid
9+ const { id} = props
10+
11+ const pg = createSupabaseDirectClient ( )
12+
13+ // Only allow deleting your own bookmarked searches
14+ await pg . none (
15+ `
16+ DELETE FROM bookmarked_searches
17+ WHERE id = $1 AND creator_id = $2
18+ ` ,
19+ [ id , creator_id ]
20+ )
21+
22+ return { }
23+ }
Original file line number Diff line number Diff line change @@ -595,6 +595,15 @@ export const API = (_apiTypeCheck = {
595595 search_name : z . string ( ) . nullable ( ) . optional ( ) ,
596596 } ) ,
597597 } ,
598+ 'delete-bookmarked-search' : {
599+ method : 'POST' ,
600+ authed : true ,
601+ rateLimited : true ,
602+ returns : { } as any ,
603+ props : z . object ( {
604+ id : z . number ( ) ,
605+ } ) ,
606+ } ,
598607} as const )
599608
600609export type APIPath = keyof typeof API
Original file line number Diff line number Diff line change @@ -46,9 +46,6 @@ export const deleteBookmarkedSearch = async (
4646 id : number ,
4747) => {
4848 if ( ! id ) return
49- await run (
50- db . from ( 'bookmarked_searches' ) . delete ( ) . eq ( 'id' , id )
51- ) . then ( ( ) => {
52- track ( 'bookmarked_searches delete' , { id} )
53- } )
49+ await api ( 'delete-bookmarked-search' , { id} )
50+ track ( 'bookmarked_searches delete' , { id} )
5451}
You can’t perform that action at this time.
0 commit comments