mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
"use strict";
|
|
|
|
const repository = require('./repository');
|
|
const Label = require('../entities/label');
|
|
|
|
const BUILTIN_LABELS = [
|
|
'disableVersioning',
|
|
'calendarRoot',
|
|
'hideInAutocomplete',
|
|
'excludeFromExport',
|
|
'run',
|
|
'manualTransactionHandling',
|
|
'disableInclusion',
|
|
'appCss',
|
|
'hideChildrenOverview'
|
|
];
|
|
|
|
async function getNotesWithLabel(name, value) {
|
|
let notes;
|
|
|
|
if (value !== undefined) {
|
|
notes = await repository.getEntities(`SELECT notes.* FROM notes JOIN labels USING(noteId)
|
|
WHERE notes.isDeleted = 0 AND labels.isDeleted = 0 AND labels.name = ? AND labels.value = ?`, [name, value]);
|
|
}
|
|
else {
|
|
notes = await repository.getEntities(`SELECT notes.* FROM notes JOIN labels USING(noteId)
|
|
WHERE notes.isDeleted = 0 AND labels.isDeleted = 0 AND labels.name = ?`, [name]);
|
|
}
|
|
|
|
return notes;
|
|
}
|
|
|
|
async function getNoteWithLabel(name, value) {
|
|
const notes = await getNotesWithLabel(name, value);
|
|
|
|
return notes.length > 0 ? notes[0] : null;
|
|
}
|
|
|
|
async function createLabel(noteId, name, value = "") {
|
|
return await new Label({
|
|
noteId: noteId,
|
|
name: name,
|
|
value: value
|
|
}).save();
|
|
}
|
|
|
|
module.exports = {
|
|
getNotesWithLabel,
|
|
getNoteWithLabel,
|
|
createLabel,
|
|
BUILTIN_LABELS
|
|
}; |