diff --git a/packages/lib/services/rest/routes/folders.test.ts b/packages/lib/services/rest/routes/folders.test.ts index 77886ed44..50f0a4944 100644 --- a/packages/lib/services/rest/routes/folders.test.ts +++ b/packages/lib/services/rest/routes/folders.test.ts @@ -25,6 +25,34 @@ describe('routes/folders', () => { expect(page.items[0].id).toBe(folder2.id); }); + test('should not include deleted folders in GET folders/:id/notes call', async () => { + const api = new Api(); + const folder = await Folder.save({}); + const note1 = await Note.save({ parent_id: folder.id }); + const note2 = await Note.save({ parent_id: folder.id }); + + { + const notes = await api.route(RequestMethod.GET, `folders/${folder.id}/notes`); + expect(notes.items.length).toBe(2); + } + + await Note.delete(note1.id, { toTrash: true }); + + { + const notes = await api.route(RequestMethod.GET, `folders/${folder.id}/notes`); + expect(notes.items.length).toBe(1); + expect(notes.items[0].id).toBe(note2.id); + } + + // const tree = await api.route(RequestMethod.GET, 'folders', { as_tree: 1 }); + // expect(tree.length).toBe(1); + // expect(tree[0].id).toBe(folder2.id); + + // const page = await api.route(RequestMethod.GET, 'folders'); + // expect(page.items.length).toBe(1); + // expect(page.items[0].id).toBe(folder2.id); + }); + test('should be able to delete to trash', async () => { const api = new Api(); const folder1 = await Folder.save({}); diff --git a/packages/lib/services/rest/routes/folders.ts b/packages/lib/services/rest/routes/folders.ts index d66b8cfb1..a49559b39 100644 --- a/packages/lib/services/rest/routes/folders.ts +++ b/packages/lib/services/rest/routes/folders.ts @@ -25,7 +25,7 @@ export default async function(request: Request, id: string = null, link: string if (request.method === RequestMethod.GET && id) { if (link && link === 'notes') { const folder = await Folder.load(id); - return paginatedResults(BaseModel.TYPE_NOTE, request, { sql: 'parent_id = ?', params: [folder.id] }); + return paginatedResults(BaseModel.TYPE_NOTE, request, { sql: 'parent_id = ? AND deleted_time = 0', params: [folder.id] }); } else if (link) { throw new ErrorNotFound(); }