small script API additions

This commit is contained in:
zadam
2019-11-27 23:07:10 +01:00
parent 0415efd33b
commit 1c057cac75
7 changed files with 307 additions and 9 deletions

View File

@@ -778,6 +778,16 @@ class Note extends Entity {
return notePaths;
}
/**
* @param ancestorNoteId
* @return {Promise<boolean>} - true if ancestorNoteId occurs in at least one of the note's paths
*/
async isDescendantOfNote(ancestorNoteId) {
const notePaths = await this.getAllNotePaths();
return notePaths.some(path => path.includes(ancestorNoteId));
}
beforeSaving() {
if (!this.isDeleted) {
this.isDeleted = false;

View File

@@ -254,6 +254,14 @@ function BackendScriptApi(currentNote, apiParams) {
*/
this.getDateNote = dateNoteService.getDateNote;
/**
* Returns today's day note. If such note doesn't exist, it is created.
*
* @method
* @returns {Promise<Note|null>}
*/
this.getTodayNote = dateNoteService.getTodayNote;
/**
* Returns note for the first date of the week of the given date.
*

View File

@@ -170,6 +170,10 @@ async function getDateNote(dateStr) {
return dateNote;
}
async function getTodayNote() {
return await getDateNote(dateUtils.localNowDate());
}
function getStartOfTheWeek(date, startOfTheWeek) {
const day = date.getDay();
let diff;
@@ -202,5 +206,6 @@ module.exports = {
getYearNote,
getMonthNote,
getWeekNote,
getDateNote
getDateNote,
getTodayNote
};