Skip to content

Commit

Permalink
Api: Do not return deleted notes in folders/:id/notes call
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent22 committed Jul 3, 2024
1 parent 4a475f1 commit 3e0fb48
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions packages/lib/services/rest/routes/folders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({});
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/services/rest/routes/folders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 3e0fb48

Please sign in to comment.