Notes/src/routes/api/recent_notes.js

44 lines
1.0 KiB
JavaScript
Raw Normal View History

2017-11-04 23:46:50 -04:00
"use strict";
2018-04-01 12:03:21 -04:00
const repository = require('../../services/repository');
2017-11-04 23:46:50 -04:00
const utils = require('../../services/utils');
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(`
SELECT
recent_notes.*
FROM
recent_notes
2018-03-24 21:39:15 -04:00
JOIN branches USING(branchId)
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
ORDER BY
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-01 12:03:21 -04:00
const recentNote = new RecentNote({
2018-03-30 15:34:07 -04:00
branchId: branchId,
notePath: notePath,
dateAccessed: utils.nowDate(),
isDeleted: 0
});
2018-04-01 12:03:21 -04:00
await recentNote.save();
2018-03-30 15:34:07 -04:00
await optionService.setOption('start_note_path', notePath);
2018-03-30 15:34:07 -04:00
return await getRecentNotes();
}
module.exports = {
getRecentNotes,
addRecentNote
};