Skip to content

Commit

Permalink
feat(api): add snippets batch delete
Browse files Browse the repository at this point in the history
  • Loading branch information
antonreshetov committed Apr 7, 2022
1 parent 2f55391 commit f27295a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/main/services/api/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ export const createApiServer = () => {
}
})

app.post('/snippets/delete', (req, res) => {
const ids: string[] = req.body.ids
const snippets = router.db.get<Snippet[]>('snippets').value()

ids.forEach(i => {
const index = snippets.findIndex(s => s.id === i)
if (index !== -1) snippets.splice(index, 1)
})

router.db.write()

res.sendStatus(200)
})

app.delete('/tags/:id', (req, res) => {
const id = req.params.id
const tags = router.db.get<Tag[]>('tags').value()
Expand Down
4 changes: 1 addition & 3 deletions src/renderer/store/snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,7 @@ export const useSnippetStore = defineStore('snippets', {
await useApi(`/snippets/${id}`).delete()
},
async deleteSnippetsByIds (ids: string[]) {
for (const id of ids) {
await useApi(`/snippets/${id}`).delete()
}
await useApi('/snippets/delete').post({ ids })
},
async setSnippetsByFolderIds (setFirst?: boolean) {
const folderStore = useFolderStore()
Expand Down

0 comments on commit f27295a

Please sign in to comment.