2018-03-24 22:02:26 -04:00
|
|
|
"use strict";
|
|
|
|
|
2018-03-31 09:07:58 -04:00
|
|
|
const repository = require('./repository');
|
2018-03-31 23:19:54 -04:00
|
|
|
const Label = require('../entities/label');
|
2018-03-24 22:02:26 -04:00
|
|
|
|
|
|
|
const BUILTIN_LABELS = [
|
2018-04-02 21:56:55 -04:00
|
|
|
'disableVersioning',
|
|
|
|
'calendarRoot',
|
2018-06-07 19:26:28 -04:00
|
|
|
'archived',
|
2018-04-02 21:56:55 -04:00
|
|
|
'excludeFromExport',
|
2018-03-24 22:02:26 -04:00
|
|
|
'run',
|
2018-04-02 21:56:55 -04:00
|
|
|
'manualTransactionHandling',
|
|
|
|
'disableInclusion',
|
2018-04-10 23:15:41 -04:00
|
|
|
'appCss',
|
|
|
|
'hideChildrenOverview'
|
2018-03-24 22:02:26 -04:00
|
|
|
];
|
|
|
|
|
2018-03-31 09:07:58 -04:00
|
|
|
async function getNotesWithLabel(name, value) {
|
2018-03-24 22:02:26 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-03-31 09:07:58 -04:00
|
|
|
async function getNoteWithLabel(name, value) {
|
2018-04-04 23:43:54 -04:00
|
|
|
const notes = await getNotesWithLabel(name, value);
|
2018-03-24 22:02:26 -04:00
|
|
|
|
|
|
|
return notes.length > 0 ? notes[0] : null;
|
|
|
|
}
|
|
|
|
|
2018-03-30 19:41:54 -04:00
|
|
|
async function createLabel(noteId, name, value = "") {
|
2018-04-02 22:53:01 -04:00
|
|
|
return await new Label({
|
2018-03-24 22:02:26 -04:00
|
|
|
noteId: noteId,
|
|
|
|
name: name,
|
2018-04-01 12:45:35 -04:00
|
|
|
value: value
|
2018-04-02 22:53:01 -04:00
|
|
|
}).save();
|
2018-03-24 22:02:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
getNotesWithLabel,
|
|
|
|
getNoteWithLabel,
|
|
|
|
createLabel,
|
|
|
|
BUILTIN_LABELS
|
|
|
|
};
|