Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
server-ts: Convert routes/api/recent_changes
Elian Doran66d7548046dd
diff --git a/src/routes/api/recent_changes.js b/src/routes/api/recent_changes.tssimilarity index 80%rename from src/routes/api/recent_changes.jsrename to src/routes/api/recent_changes.tsindex 44e964ecf0..bf662a7846 100644--- a/src/routes/api/recent_changes.js+++ b/src/routes/api/recent_changes.ts@@ -1,16 +1,30 @@"use strict";-const sql = require('../../services/sql');-const protectedSessionService = require('../../services/protected_session');-const noteService = require('../../services/notes');-const becca = require('../../becca/becca');+import sql = require('../../services/sql');+import protectedSessionService = require('../../services/protected_session');+import noteService = require('../../services/notes');+import becca = require('../../becca/becca');+import { Request } from 'express';+import { RevisionRow } from '../../becca/entities/rows';++interface RecentChangeRow {+ noteId: string;+ current_isDeleted: boolean;+ current_deleteId: string;+ current_title: string;+ current_isProtected: boolean,+ title: string;+ utcDate: string;+ date: string;+ canBeUndeleted?: boolean;+}-function getRecentChanges(req) {+function getRecentChanges(req: Request) {const {ancestorNoteId} = req.params;let recentChanges = [];- const revisionRows = sql.getRows(`+ const revisionRows = sql.getRows<RecentChangeRow>(`SELECTnotes.noteId,notes.isDeleted AS current_isDeleted,@@ -36,7 +50,7 @@ function getRecentChanges(req) {// now we need to also collect date points not represented in note revisions:// 1. creation for all notes (dateCreated)// 2. deletion for deleted notes (dateModified)- const noteRows = sql.getRows(`+ const noteRows = sql.getRows<RecentChangeRow>(`SELECTnotes.noteId,notes.isDeleted AS current_isDeleted,@@ -76,8 +90,8 @@ function getRecentChanges(req) {for (const change of recentChanges) {if (change.current_isProtected) {if (protectedSessionService.isProtectedSessionAvailable()) {- change.title = protectedSessionService.decryptString(change.title);- change.current_title = protectedSessionService.decryptString(change.current_title);+ change.title = protectedSessionService.decryptString(change.title) || "[protected]";+ change.current_title = protectedSessionService.decryptString(change.current_title) || "[protected]";}else {change.title = change.current_title = "[protected]";@@ -97,6 +111,6 @@ function getRecentChanges(req) {return recentChanges;}-module.exports = {+export = {getRecentChanges};diff --git a/src/routes/routes.js b/src/routes/routes.jsindex d918c0476d..d8bda744af 100644--- a/src/routes/routes.js+++ b/src/routes/routes.js@@ -29,7 +29,7 @@ const attachmentsApiRoute = require('./api/attachments');const autocompleteApiRoute = require('./api/autocomplete');const cloningApiRoute = require('./api/cloning');const revisionsApiRoute = require('./api/revisions');-const recentChangesApiRoute = require('./api/recent_changes.js');+const recentChangesApiRoute = require('./api/recent_changes');const optionsApiRoute = require('./api/options');const passwordApiRoute = require('./api/password');const syncApiRoute = require('./api/sync');