Notes/src/routes/api/recent_notes.js

24 lines
643 B
JavaScript
Raw Normal View History

2017-11-04 23:46:50 -04:00
"use strict";
2021-05-02 19:59:16 +02:00
const RecentNote = require('../../services/becca/entities/recent_note.js');
2021-02-12 22:39:38 +01:00
const sql = require('../../services/sql');
const dateUtils = require('../../services/date_utils');
2017-11-04 23:46:50 -04:00
2020-06-20 12:31:38 +02:00
function addRecentNote(req) {
new RecentNote({
noteId: req.body.noteId,
notePath: req.body.notePath
2018-04-02 22:53:01 -04:00
}).save();
2021-02-12 22:39:38 +01:00
if (Math.random() < 0.05) {
// it's not necessary to run this everytime ...
const cutOffDate = dateUtils.utcDateStr(new Date(Date.now() - 24 * 3600 * 1000));
sql.execute(`DELETE FROM recent_notes WHERE utcDateCreated < ?`, [cutOffDate]);
}
2018-03-30 15:34:07 -04:00
}
module.exports = {
addRecentNote
2020-06-20 12:31:38 +02:00
};