1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-21 09:38:01 +02:00

Api: Do not return deleted notes in folders/:id/notes call

This commit is contained in:
Laurent Cozic 2024-07-03 10:41:31 +02:00
parent 4a475f1b53
commit 3e0fb48e44
2 changed files with 29 additions and 1 deletions

View File

@ -25,6 +25,34 @@ describe('routes/folders', () => {
expect(page.items[0].id).toBe(folder2.id); 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 () => { test('should be able to delete to trash', async () => {
const api = new Api(); const api = new Api();
const folder1 = await Folder.save({}); const folder1 = await Folder.save({});

View File

@ -25,7 +25,7 @@ export default async function(request: Request, id: string = null, link: string
if (request.method === RequestMethod.GET && id) { if (request.method === RequestMethod.GET && id) {
if (link && link === 'notes') { if (link && link === 'notes') {
const folder = await Folder.load(id); 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) { } else if (link) {
throw new ErrorNotFound(); throw new ErrorNotFound();
} }