From 66d7548046dd17b467a2cf81722b67e555f4a5d8 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 6 Apr 2024 22:07:03 +0300 Subject: [PATCH] server-ts: Convert routes/api/recent_changes --- .../{recent_changes.js => recent_changes.ts} | 34 +++++++++++++------ src/routes/routes.js | 2 +- 2 files changed, 25 insertions(+), 11 deletions(-) rename src/routes/api/{recent_changes.js => recent_changes.ts} (80%) diff --git a/src/routes/api/recent_changes.js b/src/routes/api/recent_changes.ts similarity index 80% rename from src/routes/api/recent_changes.js rename to src/routes/api/recent_changes.ts index 44e964ecf..bf662a784 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'; -function getRecentChanges(req) { +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: Request) { const {ancestorNoteId} = req.params; let recentChanges = []; - const revisionRows = sql.getRows(` + const revisionRows = sql.getRows(` SELECT notes.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(` SELECT notes.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.js index d918c0476..d8bda744a 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');