2019-04-14 12:18:52 +02:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const dateNoteService = require('../../services/date_notes');
|
2019-09-08 16:30:33 +02:00
|
|
|
const sql = require('../../services/sql');
|
2020-05-08 23:39:46 +02:00
|
|
|
const dateUtils = require('../../services/date_utils');
|
|
|
|
const noteService = require('../../services/notes');
|
2019-04-14 12:18:52 +02:00
|
|
|
|
2020-06-20 12:31:38 +02:00
|
|
|
function getDateNote(req) {
|
|
|
|
return dateNoteService.getDateNote(req.params.date);
|
2019-04-14 12:18:52 +02:00
|
|
|
}
|
|
|
|
|
2020-06-20 12:31:38 +02:00
|
|
|
function getMonthNote(req) {
|
|
|
|
return dateNoteService.getMonthNote(req.params.month);
|
2019-04-14 12:18:52 +02:00
|
|
|
}
|
|
|
|
|
2020-06-20 12:31:38 +02:00
|
|
|
function getYearNote(req) {
|
|
|
|
return dateNoteService.getYearNote(req.params.year);
|
2019-04-14 12:18:52 +02:00
|
|
|
}
|
|
|
|
|
2020-06-20 12:31:38 +02:00
|
|
|
function getDateNotesForMonth(req) {
|
2019-09-08 16:30:33 +02:00
|
|
|
const month = req.params.month;
|
|
|
|
|
|
|
|
return sql.getMap(`
|
|
|
|
SELECT
|
|
|
|
attr.value AS date,
|
|
|
|
notes.noteId
|
|
|
|
FROM notes
|
|
|
|
JOIN attributes attr USING(noteId)
|
|
|
|
WHERE notes.isDeleted = 0
|
|
|
|
AND attr.isDeleted = 0
|
|
|
|
AND attr.type = 'label'
|
|
|
|
AND attr.name = 'dateNote'
|
|
|
|
AND attr.value LIKE '${month}%'`);
|
|
|
|
}
|
|
|
|
|
2020-06-20 12:31:38 +02:00
|
|
|
function createSqlConsole() {
|
2020-05-08 23:39:46 +02:00
|
|
|
const today = dateUtils.localNowDate();
|
|
|
|
|
2020-06-20 12:31:38 +02:00
|
|
|
const todayNote = dateNoteService.getDateNote(today);
|
2020-05-08 23:39:46 +02:00
|
|
|
|
2020-06-20 12:31:38 +02:00
|
|
|
const {note} = noteService.createNewNote({
|
2020-05-08 23:39:46 +02:00
|
|
|
parentNoteId: todayNote.noteId,
|
|
|
|
title: 'SQL Console',
|
|
|
|
content: "SELECT title, isDeleted, isProtected FROM notes WHERE noteId = ''\n\n\n\n",
|
|
|
|
type: 'code',
|
|
|
|
mime: 'text/x-sqlite;schema=trilium'
|
|
|
|
});
|
|
|
|
|
2020-06-20 12:31:38 +02:00
|
|
|
note.setLabel("sqlConsole", today);
|
2020-05-08 23:39:46 +02:00
|
|
|
|
|
|
|
return note;
|
|
|
|
}
|
|
|
|
|
2020-10-25 23:02:12 +01:00
|
|
|
function createSearchNote() {
|
|
|
|
const today = dateUtils.localNowDate();
|
|
|
|
|
|
|
|
const todayNote = dateNoteService.getDateNote(today);
|
|
|
|
|
|
|
|
const {note} = noteService.createNewNote({
|
|
|
|
parentNoteId: todayNote.noteId,
|
|
|
|
title: 'Search',
|
|
|
|
content: "",
|
|
|
|
type: 'search',
|
|
|
|
mime: 'application/json'
|
|
|
|
});
|
|
|
|
|
|
|
|
return note;
|
|
|
|
}
|
|
|
|
|
2019-04-14 12:18:52 +02:00
|
|
|
module.exports = {
|
|
|
|
getDateNote,
|
|
|
|
getMonthNote,
|
2019-09-08 16:30:33 +02:00
|
|
|
getYearNote,
|
2020-05-08 23:39:46 +02:00
|
|
|
getDateNotesForMonth,
|
2020-10-25 23:02:12 +01:00
|
|
|
createSqlConsole,
|
|
|
|
createSearchNote
|
2020-06-20 12:31:38 +02:00
|
|
|
};
|