You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-06 09:19:22 +02:00
This commit is contained in:
@@ -109,6 +109,22 @@ describe('services_rest_Api', () => {
|
||||
expect(response.items.length).toBe(2);
|
||||
}));
|
||||
|
||||
it('should return folders as a tree', async () => {
|
||||
const folder1 = await Folder.save({ title: 'Folder 1' });
|
||||
await Folder.save({ title: 'Folder 2', parent_id: folder1.id });
|
||||
await Folder.save({ title: 'Folder 3', parent_id: folder1.id });
|
||||
|
||||
const response = await api.route(RequestMethod.GET, 'folders', { as_tree: 1 });
|
||||
expect(response).toMatchObject([{
|
||||
title: 'Folder 1',
|
||||
id: folder1.id,
|
||||
children: [
|
||||
{ title: 'Folder 2' },
|
||||
{ title: 'Folder 3' },
|
||||
],
|
||||
}]);
|
||||
});
|
||||
|
||||
it('should fail on invalid paths', (async () => {
|
||||
const hasThrown = await checkThrowAsync(async () => await api.route(RequestMethod.GET, 'schtroumpf'));
|
||||
expect(hasThrown).toBe(true);
|
||||
|
||||
@@ -5,13 +5,13 @@ import paginatedResults from '../utils/paginatedResults';
|
||||
import BaseModel from '../../../BaseModel';
|
||||
import requestFields from '../utils/requestFields';
|
||||
import Folder from '../../../models/Folder';
|
||||
const { FoldersScreenUtils } = require('../../../folders-screen-utils.js');
|
||||
import { allForDisplay } from '../../../folders-screen-utils';
|
||||
const { ErrorNotFound } = require('../utils/errors');
|
||||
|
||||
export default async function(request: Request, id: string = null, link: string = null) {
|
||||
if (request.method === 'GET' && !id) {
|
||||
if (request.query.as_tree) {
|
||||
const folders = await FoldersScreenUtils.allForDisplay({ fields: requestFields(request, BaseModel.TYPE_FOLDER) });
|
||||
const folders = await allForDisplay({ fields: requestFields(request, BaseModel.TYPE_FOLDER) });
|
||||
const output = await Folder.allAsTree(folders);
|
||||
return output;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user