server-ts: Convert routes/api/recent_changes

This commit is contained in:
Elian Doran 2024-04-06 22:07:03 +03:00
parent 4b1c351195
commit 66d7548046
No known key found for this signature in database
2 changed files with 25 additions and 11 deletions

View File

@ -1,16 +1,30 @@
"use strict"; "use strict";
const sql = require('../../services/sql'); import sql = require('../../services/sql');
const protectedSessionService = require('../../services/protected_session'); import protectedSessionService = require('../../services/protected_session');
const noteService = require('../../services/notes'); import noteService = require('../../services/notes');
const becca = require('../../becca/becca'); 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; const {ancestorNoteId} = req.params;
let recentChanges = []; let recentChanges = [];
const revisionRows = sql.getRows(` const revisionRows = sql.getRows<RecentChangeRow>(`
SELECT SELECT
notes.noteId, notes.noteId,
notes.isDeleted AS current_isDeleted, 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: // now we need to also collect date points not represented in note revisions:
// 1. creation for all notes (dateCreated) // 1. creation for all notes (dateCreated)
// 2. deletion for deleted notes (dateModified) // 2. deletion for deleted notes (dateModified)
const noteRows = sql.getRows(` const noteRows = sql.getRows<RecentChangeRow>(`
SELECT SELECT
notes.noteId, notes.noteId,
notes.isDeleted AS current_isDeleted, notes.isDeleted AS current_isDeleted,
@ -76,8 +90,8 @@ function getRecentChanges(req) {
for (const change of recentChanges) { for (const change of recentChanges) {
if (change.current_isProtected) { if (change.current_isProtected) {
if (protectedSessionService.isProtectedSessionAvailable()) { if (protectedSessionService.isProtectedSessionAvailable()) {
change.title = protectedSessionService.decryptString(change.title); change.title = protectedSessionService.decryptString(change.title) || "[protected]";
change.current_title = protectedSessionService.decryptString(change.current_title); change.current_title = protectedSessionService.decryptString(change.current_title) || "[protected]";
} }
else { else {
change.title = change.current_title = "[protected]"; change.title = change.current_title = "[protected]";
@ -97,6 +111,6 @@ function getRecentChanges(req) {
return recentChanges; return recentChanges;
} }
module.exports = { export = {
getRecentChanges getRecentChanges
}; };

View File

@ -29,7 +29,7 @@ const attachmentsApiRoute = require('./api/attachments');
const autocompleteApiRoute = require('./api/autocomplete'); const autocompleteApiRoute = require('./api/autocomplete');
const cloningApiRoute = require('./api/cloning'); const cloningApiRoute = require('./api/cloning');
const revisionsApiRoute = require('./api/revisions'); const revisionsApiRoute = require('./api/revisions');
const recentChangesApiRoute = require('./api/recent_changes.js'); const recentChangesApiRoute = require('./api/recent_changes');
const optionsApiRoute = require('./api/options'); const optionsApiRoute = require('./api/options');
const passwordApiRoute = require('./api/password'); const passwordApiRoute = require('./api/password');
const syncApiRoute = require('./api/sync'); const syncApiRoute = require('./api/sync');