server-ts: Convert routes/api/recent_notes

This commit is contained in:
Elian Doran
2024-04-06 22:07:58 +03:00
parent 66d7548046
commit 96c8c9080d
2 changed files with 7 additions and 6 deletions

View File

@@ -0,0 +1,24 @@
"use strict";
import BRecentNote = require('../../becca/entities/brecent_note');
import sql = require('../../services/sql');
import dateUtils = require('../../services/date_utils');
import { Request } from 'express';
function addRecentNote(req: Request) {
new BRecentNote({
noteId: req.body.noteId,
notePath: req.body.notePath
}).save();
if (Math.random() < 0.05) {
// it's not necessary to run this every time ...
const cutOffDate = dateUtils.utcDateTimeStr(new Date(Date.now() - 24 * 3600 * 1000));
sql.execute(`DELETE FROM recent_notes WHERE utcDateCreated < ?`, [cutOffDate]);
}
}
export = {
addRecentNote
};