1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Api: Exclude deleted and conflicted notes when calling /notes

This commit is contained in:
Laurent Cozic 2024-05-03 16:14:04 +01:00
parent f1691b7743
commit 57c316a591
5 changed files with 49 additions and 6 deletions

View File

@ -239,11 +239,6 @@ async function fetchAllNotes() {
type: Database.enumId('fieldType', 'text'),
description: 'If an image is provided, you can also specify an optional rectangle that will be used to crop the image. In format `{ x: x, y: y, width: width, height: height }`',
});
// tableFields.push({
// name: 'tags',
// type: Database.enumId('fieldType', 'text'),
// description: 'Comma-separated list of tags. eg. `tag1,tag2`.',
// });
}
lines.push(`## ${toTitleCase(tableName)}`);
@ -269,6 +264,11 @@ async function fetchAllNotes() {
lines.push('');
}
if (model.type === BaseModel.TYPE_NOTE) {
lines.push('By default, this call will return the all notes **except** the notes in the trash folder and any conflict note. To include these too, you can specify `include_deleted=1` and `include_conflicts=1` as query parameters.');
lines.push('');
}
lines.push(`### GET /${tableName}/:id`);
lines.push('');
lines.push(`Gets ${singular} with ID :id`);

View File

@ -51,6 +51,8 @@ interface RequestQuery {
// For note deletion
permanent?: string;
include_deleted?: string;
include_conflicts?: string;
}
export interface Request {

View File

@ -184,4 +184,40 @@ describe('routes/notes', () => {
expect(result.length).toBe(2);
});
test('should not return notes in the trash by default', async () => {
const api = new Api();
const note1 = await Note.save({});
const note2 = await Note.save({});
await Note.delete(note1.id, { toTrash: true });
{
const notes = await api.route(RequestMethod.GET, 'notes');
expect(notes.items.length).toBe(1);
expect(notes.items[0].id).toBe(note2.id);
}
{
const notes = await api.route(RequestMethod.GET, 'notes', { include_deleted: '1' });
expect(notes.items.length).toBe(2);
}
});
test('should not return conflicts by default', async () => {
const api = new Api();
const note1 = await Note.save({});
await Note.save({ is_conflict: 1 });
{
const notes = await api.route(RequestMethod.GET, 'notes');
expect(notes.items.length).toBe(1);
expect(notes.items[0].id).toBe(note1.id);
}
{
const notes = await api.route(RequestMethod.GET, 'notes', { include_conflicts: '1' });
expect(notes.items.length).toBe(2);
}
});
});

View File

@ -478,7 +478,10 @@ export default async function(request: Request, id: string = null, link: string
throw new ErrorNotFound();
}
return defaultAction(BaseModel.TYPE_NOTE, request, id, link);
const sql: string[] = [];
if (request.query.include_deleted !== '1') sql.push('deleted_time = 0');
if (request.query.include_conflicts !== '1') sql.push('is_conflict = 0');
return defaultAction(BaseModel.TYPE_NOTE, request, id, link, null, { sql: sql.join(' AND ') });
}
if (request.method === RequestMethod.POST) {

View File

@ -212,6 +212,8 @@ command | 16
Gets all notes
By default, this call will return the all notes **except** the notes in the trash folder and any conflict note. To include these too, you can specify `include_deleted=1` and `include_conflicts=1` as query parameters.
### GET /notes/:id
Gets note with ID :id