(userId: string, noteId: string)
| 2 | import { store } from 'lib/store'; |
| 3 | import supabase from 'lib/supabase'; |
| 4 | import { getUserAssetPaths } from 'lib/storage/userAssets'; |
| 5 | |
| 6 | export default async function deleteNote(userId: string, noteId: string) { |
| 7 | const noteAssetPaths = await getNoteAssetPaths(userId, noteId); |
| 8 | |
| 9 | // Update note titles in sidebar |
| 10 | store.getState().deleteNote(noteId); |
| 11 | |
| 12 | const response = await supabase.from('notes').delete().eq('id', noteId); |
| 13 | |
| 14 | if (!response.error && noteAssetPaths.length > 0) { |
| 15 | const referencedAssetPaths = await getReferencedAssetPaths(userId); |
| 16 | if (referencedAssetPaths) { |
| 17 | const assetPathsToDelete = noteAssetPaths.filter( |
| 18 | (path) => !referencedAssetPaths.has(path) |
| 19 | ); |
no outgoing calls
no test coverage detected