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');
|
2018-04-02 09:27:46 +08:00
|
|
|
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(`
|
2017-12-19 11:37:31 +08:00
|
|
|
SELECT
|
|
|
|
recent_notes.*
|
|
|
|
FROM
|
|
|
|
recent_notes
|
2018-03-25 09:39:15 +08:00
|
|
|
JOIN branches USING(branchId)
|
2017-12-19 11:37:31 +08:00
|
|
|
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
|
2017-12-19 11:37:31 +08:00
|
|
|
ORDER BY
|
2018-02-12 04:33:10 +08:00
|
|
|
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
|
|
|
|
2018-04-03 09:47:46 +08:00
|
|
|
await optionService.setOption('startNotePath', notePath);
|
2018-03-31 03:34:07 +08:00
|
|
|
|
|
|
|
return await getRecentNotes();
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
getRecentNotes,
|
|
|
|
addRecentNote
|
|
|
|
};
|