Notes/src/services/labels.js

52 lines
1.3 KiB
JavaScript
Raw Normal View History

"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');
const BUILTIN_LABELS = [
2018-04-02 21:56:55 -04:00
'disableVersioning',
'calendarRoot',
'archived',
2018-04-02 21:56:55 -04:00
'excludeFromExport',
'run',
2018-04-02 21:56:55 -04:00
'manualTransactionHandling',
'disableInclusion',
'appCss',
'hideChildrenOverview'
];
2018-03-31 09:07:58 -04:00
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;
}
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);
return notes.length > 0 ? notes[0] : null;
}
async function createLabel(noteId, name, value = "") {
2018-04-02 22:53:01 -04:00
return await new Label({
noteId: noteId,
name: name,
2018-04-01 12:45:35 -04:00
value: value
2018-04-02 22:53:01 -04:00
}).save();
}
module.exports = {
getNotesWithLabel,
getNoteWithLabel,
createLabel,
BUILTIN_LABELS
};