mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-11-04 15:11:31 +08:00 
			
		
		
		
	server-ts: Convert routes/api/bulk_action
This commit is contained in:
		
							parent
							
								
									fd77c5e8c4
								
							
						
					
					
						commit
						40ef533c5f
					
				@ -2,7 +2,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import fs = require('fs');
 | 
					import fs = require('fs');
 | 
				
			||||||
import dateUtils = require('../../services/date_utils');
 | 
					import dateUtils = require('../../services/date_utils');
 | 
				
			||||||
import dataDir = require('../../services/data_dir.js');
 | 
					import dataDir = require('../../services/data_dir');
 | 
				
			||||||
const { LOG_DIR } = dataDir;
 | 
					const { LOG_DIR } = dataDir;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function getBackendLog() {
 | 
					function getBackendLog() {
 | 
				
			||||||
 | 
				
			|||||||
@ -1,17 +1,18 @@
 | 
				
			|||||||
const becca = require('../../becca/becca');
 | 
					import { Request } from 'express';
 | 
				
			||||||
const bulkActionService = require('../../services/bulk_actions');
 | 
					import becca = require('../../becca/becca');
 | 
				
			||||||
 | 
					import bulkActionService = require('../../services/bulk_actions');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function execute(req) {
 | 
					function execute(req: Request) {
 | 
				
			||||||
    const {noteIds, includeDescendants} = req.body;
 | 
					    const {noteIds, includeDescendants} = req.body;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const affectedNoteIds = getAffectedNoteIds(noteIds, includeDescendants);
 | 
					    const affectedNoteIds = getAffectedNoteIds(noteIds, includeDescendants);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const bulkActionNote = becca.getNote('_bulkAction');
 | 
					    const bulkActionNote = becca.getNoteOrThrow('_bulkAction');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    bulkActionService.executeActions(bulkActionNote, affectedNoteIds);
 | 
					    bulkActionService.executeActions(bulkActionNote, affectedNoteIds);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function getAffectedNoteCount(req) {
 | 
					function getAffectedNoteCount(req: Request) {
 | 
				
			||||||
    const {noteIds, includeDescendants} = req.body;
 | 
					    const {noteIds, includeDescendants} = req.body;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const affectedNoteIds = getAffectedNoteIds(noteIds, includeDescendants);
 | 
					    const affectedNoteIds = getAffectedNoteIds(noteIds, includeDescendants);
 | 
				
			||||||
@ -21,8 +22,8 @@ function getAffectedNoteCount(req) {
 | 
				
			|||||||
    };
 | 
					    };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function getAffectedNoteIds(noteIds, includeDescendants) {
 | 
					function getAffectedNoteIds(noteIds: string[], includeDescendants: boolean) {
 | 
				
			||||||
    const affectedNoteIds = new Set();
 | 
					    const affectedNoteIds = new Set<string>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (const noteId of noteIds) {
 | 
					    for (const noteId of noteIds) {
 | 
				
			||||||
        const note = becca.getNote(noteId);
 | 
					        const note = becca.getNote(noteId);
 | 
				
			||||||
@ -42,7 +43,7 @@ function getAffectedNoteIds(noteIds, includeDescendants) {
 | 
				
			|||||||
    return affectedNoteIds;
 | 
					    return affectedNoteIds;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports = {
 | 
					export = {
 | 
				
			||||||
    execute,
 | 
					    execute,
 | 
				
			||||||
    getAffectedNoteCount
 | 
					    getAffectedNoteCount
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
@ -24,7 +24,7 @@ const indexRoute = require('./index.js');
 | 
				
			|||||||
// API routes
 | 
					// API routes
 | 
				
			||||||
const treeApiRoute = require('./api/tree.js');
 | 
					const treeApiRoute = require('./api/tree.js');
 | 
				
			||||||
const notesApiRoute = require('./api/notes.js');
 | 
					const notesApiRoute = require('./api/notes.js');
 | 
				
			||||||
const branchesApiRoute = require('./api/branches.js');
 | 
					const branchesApiRoute = require('./api/branches');
 | 
				
			||||||
const attachmentsApiRoute = require('./api/attachments');
 | 
					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');
 | 
				
			||||||
@ -47,7 +47,7 @@ const scriptRoute = require('./api/script.js');
 | 
				
			|||||||
const senderRoute = require('./api/sender.js');
 | 
					const senderRoute = require('./api/sender.js');
 | 
				
			||||||
const filesRoute = require('./api/files.js');
 | 
					const filesRoute = require('./api/files.js');
 | 
				
			||||||
const searchRoute = require('./api/search');
 | 
					const searchRoute = require('./api/search');
 | 
				
			||||||
const bulkActionRoute = require('./api/bulk_action.js');
 | 
					const bulkActionRoute = require('./api/bulk_action');
 | 
				
			||||||
const specialNotesRoute = require('./api/special_notes');
 | 
					const specialNotesRoute = require('./api/special_notes');
 | 
				
			||||||
const noteMapRoute = require('./api/note_map.js');
 | 
					const noteMapRoute = require('./api/note_map.js');
 | 
				
			||||||
const clipperRoute = require('./api/clipper.js');
 | 
					const clipperRoute = require('./api/clipper.js');
 | 
				
			||||||
 | 
				
			|||||||
@ -150,7 +150,7 @@ function getActions(note: BNote) {
 | 
				
			|||||||
        .filter(a => !!a);
 | 
					        .filter(a => !!a);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function executeActions(note: BNote, searchResultNoteIds: string[]) {
 | 
					function executeActions(note: BNote, searchResultNoteIds: string[] | Set<string>) {
 | 
				
			||||||
    const actions = getActions(note);
 | 
					    const actions = getActions(note);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (const resultNoteId of searchResultNoteIds) {
 | 
					    for (const resultNoteId of searchResultNoteIds) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user