mirror of
https://github.com/zadam/trilium.git
synced 2025-11-17 02:30:42 +01:00
smaller refactorings continued
This commit is contained in:
@@ -14,12 +14,14 @@ const DAYS = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Satur
|
||||
const MONTHS = ['January','February','March','April','May','June','July','August','September','October','November','December'];
|
||||
|
||||
async function createNote(parentNoteId, noteTitle, noteText) {
|
||||
return (await notes.createNewNote(parentNoteId, {
|
||||
const {note} = await notes.createNewNote(parentNoteId, {
|
||||
title: noteTitle,
|
||||
content: noteText,
|
||||
target: 'into',
|
||||
isProtected: false
|
||||
})).noteId;
|
||||
});
|
||||
|
||||
return note.noteId;
|
||||
}
|
||||
|
||||
async function getNoteStartingWith(parentNoteId, startsWith) {
|
||||
@@ -34,11 +36,13 @@ async function getRootCalendarNoteId() {
|
||||
WHERE labels.name = '${CALENDAR_ROOT_LABEL}' AND notes.isDeleted = 0`);
|
||||
|
||||
if (!rootNoteId) {
|
||||
rootNoteId = (await notes.createNewNote('root', {
|
||||
const {rootNote} = await notes.createNewNote('root', {
|
||||
title: 'Calendar',
|
||||
target: 'into',
|
||||
isProtected: false
|
||||
})).noteId;
|
||||
});
|
||||
|
||||
const rootNoteId = rootNote.noteId;
|
||||
|
||||
await labels.createLabel(rootNoteId, CALENDAR_ROOT_LABEL);
|
||||
}
|
||||
|
||||
@@ -72,9 +72,7 @@ async function createNewNote(parentNoteId, noteOpts) {
|
||||
await branch.save();
|
||||
|
||||
return {
|
||||
noteId: note.noteId,
|
||||
note,
|
||||
branchId: branch.branchId,
|
||||
branch
|
||||
};
|
||||
}
|
||||
@@ -83,7 +81,7 @@ async function createNote(parentNoteId, title, content = "", extraOptions = {})
|
||||
if (!parentNoteId) throw new Error("Empty parentNoteId");
|
||||
if (!title) throw new Error("Empty title");
|
||||
|
||||
const note = {
|
||||
const noteData = {
|
||||
title: title,
|
||||
content: extraOptions.json ? JSON.stringify(content, null, '\t') : content,
|
||||
target: 'into',
|
||||
@@ -92,25 +90,25 @@ async function createNote(parentNoteId, title, content = "", extraOptions = {})
|
||||
mime: extraOptions.mime
|
||||
};
|
||||
|
||||
if (extraOptions.json && !note.type) {
|
||||
note.type = "code";
|
||||
note.mime = "application/json";
|
||||
if (extraOptions.json && !noteData.type) {
|
||||
noteData.type = "code";
|
||||
noteData.mime = "application/json";
|
||||
}
|
||||
|
||||
if (!note.type) {
|
||||
note.type = "text";
|
||||
note.mime = "text/html";
|
||||
if (!noteData.type) {
|
||||
noteData.type = "text";
|
||||
noteData.mime = "text/html";
|
||||
}
|
||||
|
||||
const {noteId} = await createNewNote(parentNoteId, note);
|
||||
const {note} = await createNewNote(parentNoteId, noteData);
|
||||
|
||||
if (extraOptions.labels) {
|
||||
for (const labelName in extraOptions.labels) {
|
||||
await labels.createLabel(noteId, labelName, extraOptions.labels[labelName]);
|
||||
await labels.createLabel(note.noteId, labelName, extraOptions.labels[labelName]);
|
||||
}
|
||||
}
|
||||
|
||||
return noteId;
|
||||
return note.noteId;
|
||||
}
|
||||
|
||||
async function protectNoteRecursively(note, protect) {
|
||||
|
||||
@@ -37,6 +37,10 @@ async function getImage(imageId) {
|
||||
return await getEntity("SELECT * FROM images WHERE imageId = ?", [imageId]);
|
||||
}
|
||||
|
||||
async function getLabel(labelId) {
|
||||
return await getEntity("SELECT * FROM labels WHERE labelId = ?", [labelId]);
|
||||
}
|
||||
|
||||
async function updateEntity(entity) {
|
||||
if (entity.beforeSaving) {
|
||||
entity.beforeSaving();
|
||||
@@ -59,6 +63,7 @@ module.exports = {
|
||||
getNote,
|
||||
getBranch,
|
||||
getImage,
|
||||
getLabel,
|
||||
updateEntity,
|
||||
setEntityConstructor
|
||||
};
|
||||
Reference in New Issue
Block a user