mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-27 08:16:40 +01:00 
			
		
		
		
	server-ts: Convert routes/api/relation-map
This commit is contained in:
		| @@ -1,10 +1,22 @@ | |||||||
| const becca = require('../../becca/becca'); | import { Request } from 'express'; | ||||||
| const sql = require('../../services/sql'); | import becca = require('../../becca/becca'); | ||||||
|  | import sql = require('../../services/sql'); | ||||||
| 
 | 
 | ||||||
| function getRelationMap(req) { | interface ResponseData { | ||||||
|  |     noteTitles: Record<string, string>; | ||||||
|  |     relations: { | ||||||
|  |         attributeId: string, | ||||||
|  |         sourceNoteId: string, | ||||||
|  |         targetNoteId: string, | ||||||
|  |         name: string | ||||||
|  |     }[]; | ||||||
|  |     inverseRelations: Record<string, string>; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function getRelationMap(req: Request) { | ||||||
|     const {relationMapNoteId, noteIds} = req.body; |     const {relationMapNoteId, noteIds} = req.body; | ||||||
| 
 | 
 | ||||||
|     const resp = { |     const resp: ResponseData = { | ||||||
|         // noteId => title
 |         // noteId => title
 | ||||||
|         noteTitles: {}, |         noteTitles: {}, | ||||||
|         relations: [], |         relations: [], | ||||||
| @@ -14,13 +26,13 @@ function getRelationMap(req) { | |||||||
|         } |         } | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     if (noteIds.length === 0) { |     if (!Array.isArray(noteIds) || noteIds.length === 0) { | ||||||
|         return resp; |         return resp; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     const questionMarks = noteIds.map(noteId => '?').join(','); |     const questionMarks = noteIds.map(noteId => '?').join(','); | ||||||
| 
 | 
 | ||||||
|     const relationMapNote = becca.getNote(relationMapNoteId); |     const relationMapNote = becca.getNoteOrThrow(relationMapNoteId); | ||||||
| 
 | 
 | ||||||
|     const displayRelationsVal = relationMapNote.getLabelValue('displayRelations'); |     const displayRelationsVal = relationMapNote.getLabelValue('displayRelations'); | ||||||
|     const displayRelations = !displayRelationsVal ? [] : displayRelationsVal |     const displayRelations = !displayRelationsVal ? [] : displayRelationsVal | ||||||
| @@ -32,7 +44,7 @@ function getRelationMap(req) { | |||||||
|         .split(",") |         .split(",") | ||||||
|         .map(token => token.trim()); |         .map(token => token.trim()); | ||||||
| 
 | 
 | ||||||
|     const foundNoteIds = sql.getColumn(`SELECT noteId FROM notes WHERE isDeleted = 0 AND noteId IN (${questionMarks})`, noteIds); |     const foundNoteIds = sql.getColumn<string>(`SELECT noteId FROM notes WHERE isDeleted = 0 AND noteId IN (${questionMarks})`, noteIds); | ||||||
|     const notes = becca.getNotes(foundNoteIds); |     const notes = becca.getNotes(foundNoteIds); | ||||||
| 
 | 
 | ||||||
|     for (const note of notes) { |     for (const note of notes) { | ||||||
| @@ -64,6 +76,6 @@ function getRelationMap(req) { | |||||||
|     return resp; |     return resp; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| module.exports = { | export = { | ||||||
|     getRelationMap |     getRelationMap | ||||||
| }; | }; | ||||||
		Reference in New Issue
	
	Block a user