2017-11-05 11:46:50 +08:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const sql = require('../../services/sql');
|
|
|
|
const utils = require('../../services/utils');
|
2017-11-17 10:50:00 +08:00
|
|
|
const sync_table = require('../../services/sync_table');
|
2017-11-19 06:05:50 +08:00
|
|
|
const options = require('../../services/options');
|
2017-11-05 11:46:50 +08:00
|
|
|
|
|
|
|
async function getRecentNotes() {
|
2018-01-30 06:41:59 +08:00
|
|
|
return await sql.getRows(`
|
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;
|
|
|
|
const sourceId = req.headers.source_id;
|
|
|
|
|
|
|
|
await sql.replace('recent_notes', {
|
|
|
|
branchId: branchId,
|
|
|
|
notePath: notePath,
|
|
|
|
dateAccessed: utils.nowDate(),
|
|
|
|
isDeleted: 0
|
|
|
|
});
|
|
|
|
|
|
|
|
await sync_table.addRecentNoteSync(branchId, sourceId);
|
|
|
|
|
|
|
|
await options.setOption('start_note_path', notePath, sourceId);
|
|
|
|
|
|
|
|
return await getRecentNotes();
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
getRecentNotes,
|
|
|
|
addRecentNote
|
|
|
|
};
|