trilium/src/routes/api/recent_notes.js

44 lines
1 KiB
JavaScript
Raw Normal View History

2017-11-05 11:46:50 +08:00
"use strict";
2018-04-02 00:03:21 +08:00
const repository = require('../../services/repository');
2018-04-03 08:46:46 +08:00
const dateUtils = require('../../services/date_utils');
const optionService = require('../../services/options');
2018-04-02 00:03:21 +08:00
const RecentNote = require('../../entities/recent_note');
2017-11-05 11:46:50 +08:00
async function getRecentNotes() {
2018-04-02 00:03:21 +08:00
return await repository.getEntities(`
SELECT
recent_notes.*
FROM
recent_notes
2018-03-25 09:39:15 +08:00
JOIN branches USING(branchId)
WHERE
2018-01-29 08:30:14 +08:00
recent_notes.isDeleted = 0
2018-03-25 09:39:15 +08:00
AND branches.isDeleted = 0
ORDER BY
dateAccessed DESC
LIMIT 200`);
2017-11-05 11:46:50 +08:00
}
2018-03-31 03:34:07 +08:00
async function addRecentNote(req) {
const branchId = req.params.branchId;
const notePath = req.params.notePath;
2018-04-02 00:03:21 +08:00
const recentNote = new RecentNote({
2018-03-31 03:34:07 +08:00
branchId: branchId,
notePath: notePath,
2018-04-03 08:46:46 +08:00
dateAccessed: dateUtils.nowDate(),
2018-03-31 03:34:07 +08:00
isDeleted: 0
});
2018-04-02 00:03:21 +08:00
await recentNote.save();
2018-03-31 03:34:07 +08:00
await optionService.setOption('start_note_path', notePath);
2018-03-31 03:34:07 +08:00
return await getRecentNotes();
}
module.exports = {
getRecentNotes,
addRecentNote
};