2017-10-22 09:10:33 +08:00
|
|
|
"use strict";
|
|
|
|
|
2017-10-16 07:47:05 +08:00
|
|
|
const sql = require('../../services/sql');
|
2018-04-02 09:27:46 +08:00
|
|
|
const optionService = require('../../services/options');
|
|
|
|
const protectedSessionService = require('../../services/protected_session');
|
2017-10-15 11:31:44 +08:00
|
|
|
|
2018-04-01 23:05:09 +08:00
|
|
|
async function getTree() {
|
2018-03-25 09:39:15 +08:00
|
|
|
const branches = await sql.getRows(`
|
2018-01-04 11:13:02 +08:00
|
|
|
SELECT
|
2018-03-25 09:39:15 +08:00
|
|
|
branchId,
|
2018-03-25 08:41:27 +08:00
|
|
|
noteId,
|
|
|
|
parentNoteId,
|
|
|
|
notePosition,
|
|
|
|
prefix,
|
|
|
|
isExpanded
|
|
|
|
FROM
|
2018-03-25 09:39:15 +08:00
|
|
|
branches
|
2018-01-04 11:13:02 +08:00
|
|
|
WHERE
|
2018-03-25 08:41:27 +08:00
|
|
|
isDeleted = 0
|
2018-01-04 11:13:02 +08:00
|
|
|
ORDER BY
|
2018-01-29 08:30:14 +08:00
|
|
|
notePosition`);
|
2017-11-19 07:57:50 +08:00
|
|
|
|
2018-03-31 00:57:22 +08:00
|
|
|
const notes = [{
|
2018-03-25 08:41:27 +08:00
|
|
|
noteId: 'root',
|
|
|
|
title: 'root',
|
|
|
|
isProtected: false,
|
|
|
|
type: 'none',
|
|
|
|
mime: 'none'
|
2018-03-31 00:57:22 +08:00
|
|
|
}].concat(await sql.getRows(`
|
2018-02-14 11:30:33 +08:00
|
|
|
SELECT
|
2018-03-25 08:41:27 +08:00
|
|
|
notes.noteId,
|
|
|
|
notes.title,
|
|
|
|
notes.isProtected,
|
|
|
|
notes.type,
|
|
|
|
notes.mime,
|
2018-03-25 10:02:26 +08:00
|
|
|
hideInAutocomplete.labelId AS 'hideInAutocomplete'
|
2018-03-25 08:41:27 +08:00
|
|
|
FROM
|
|
|
|
notes
|
2018-03-25 10:02:26 +08:00
|
|
|
LEFT JOIN labels AS hideInAutocomplete ON hideInAutocomplete.noteId = notes.noteId
|
2018-04-03 09:56:55 +08:00
|
|
|
AND hideInAutocomplete.name = 'hideInAutocomplete'
|
2018-03-25 08:41:27 +08:00
|
|
|
AND hideInAutocomplete.isDeleted = 0
|
|
|
|
WHERE
|
|
|
|
notes.isDeleted = 0`));
|
|
|
|
|
2018-04-02 09:27:46 +08:00
|
|
|
protectedSessionService.decryptNotes(notes);
|
2018-03-25 08:41:27 +08:00
|
|
|
|
|
|
|
notes.forEach(note => {
|
|
|
|
note.hideInAutocomplete = !!note.hideInAutocomplete;
|
|
|
|
note.isProtected = !!note.isProtected;
|
|
|
|
});
|
2018-02-14 11:30:33 +08:00
|
|
|
|
2018-03-31 00:57:22 +08:00
|
|
|
return {
|
2018-04-03 09:47:46 +08:00
|
|
|
startNotePath: await optionService.getOption('startNotePath'),
|
2018-03-25 09:39:15 +08:00
|
|
|
branches: branches,
|
2018-04-03 09:34:28 +08:00
|
|
|
notes: notes
|
2018-03-31 00:57:22 +08:00
|
|
|
};
|
|
|
|
}
|
2017-10-15 11:31:44 +08:00
|
|
|
|
2018-03-31 00:57:22 +08:00
|
|
|
module.exports = {
|
2018-04-02 08:33:10 +08:00
|
|
|
getTree
|
2018-03-31 00:57:22 +08:00
|
|
|
};
|