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
|
|
|
|
|
|
|
async function getDateNote(req) {
|
|
|
|
return await dateNoteService.getDateNote(req.params.date);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getMonthNote(req) {
|
|
|
|
return await dateNoteService.getMonthNote(req.params.month);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getYearNote(req) {
|
|
|
|
return await dateNoteService.getYearNote(req.params.year);
|
|
|
|
}
|
|
|
|
|
2019-09-08 16:30:33 +02:00
|
|
|
async function getDateNotesForMonth(req) {
|
|
|
|
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-05-08 23:39:46 +02:00
|
|
|
async function createSqlConsole() {
|
|
|
|
const today = dateUtils.localNowDate();
|
|
|
|
|
|
|
|
const todayNote = await dateNoteService.getDateNote(today);
|
|
|
|
|
|
|
|
const {note} = await noteService.createNewNote({
|
|
|
|
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'
|
|
|
|
});
|
|
|
|
|
|
|
|
await note.setLabel("sqlConsole", today);
|
|
|
|
|
|
|
|
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,
|
|
|
|
createSqlConsole
|
2019-04-14 12:18:52 +02:00
|
|
|
};
|