2017-11-04 23:46:50 -04:00
|
|
|
"use strict";
|
|
|
|
|
2018-04-01 12:03:21 -04:00
|
|
|
const repository = require('../../services/repository');
|
2018-04-02 20:46:46 -04:00
|
|
|
const dateUtils = require('../../services/date_utils');
|
2018-04-01 21:27:46 -04:00
|
|
|
const optionService = require('../../services/options');
|
2018-04-01 12:03:21 -04:00
|
|
|
const RecentNote = require('../../entities/recent_note');
|
2017-11-04 23:46:50 -04:00
|
|
|
|
|
|
|
async function getRecentNotes() {
|
2018-04-01 12:03:21 -04:00
|
|
|
return await repository.getEntities(`
|
2017-12-18 22:37:31 -05:00
|
|
|
SELECT
|
|
|
|
recent_notes.*
|
|
|
|
FROM
|
|
|
|
recent_notes
|
2018-03-24 21:39:15 -04:00
|
|
|
JOIN branches USING(branchId)
|
2017-12-18 22:37:31 -05:00
|
|
|
WHERE
|
2018-01-28 19:30:14 -05:00
|
|
|
recent_notes.isDeleted = 0
|
2018-03-24 21:39:15 -04:00
|
|
|
AND branches.isDeleted = 0
|
2017-12-18 22:37:31 -05:00
|
|
|
ORDER BY
|
2018-02-11 15:33:10 -05:00
|
|
|
dateAccessed DESC
|
|
|
|
LIMIT 200`);
|
2017-11-04 23:46:50 -04:00
|
|
|
}
|
|
|
|
|
2018-03-30 15:34:07 -04:00
|
|
|
async function addRecentNote(req) {
|
|
|
|
const branchId = req.params.branchId;
|
|
|
|
const notePath = req.params.notePath;
|
|
|
|
|
2018-04-02 22:53:01 -04:00
|
|
|
await new RecentNote({
|
2018-03-30 15:34:07 -04:00
|
|
|
branchId: branchId,
|
|
|
|
notePath: notePath,
|
2018-04-02 20:46:46 -04:00
|
|
|
dateAccessed: dateUtils.nowDate(),
|
2018-03-30 15:34:07 -04:00
|
|
|
isDeleted: 0
|
2018-04-02 22:53:01 -04:00
|
|
|
}).save();
|
2018-03-30 15:34:07 -04:00
|
|
|
|
2018-04-02 21:47:46 -04:00
|
|
|
await optionService.setOption('startNotePath', notePath);
|
2018-03-30 15:34:07 -04:00
|
|
|
|
|
|
|
return await getRecentNotes();
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
getRecentNotes,
|
|
|
|
addRecentNote
|
|
|
|
};
|