Kraft102's picture
Update backend source
34367da verified
import express from 'express';
import { VisualNodeTransformer, RawM365Email } from '../services/VisualNodeTransformer';
const router = express.Router();
// Mock data source - in a real system, this would come from a database.
const mockEmailDatabase: { [id: string]: RawM365Email } = {
'email-fysisk-sikkerhed': {
id: '000000001532ED8DFD24D446B74107272EAEAC6F07008BD4...',
title: 'Husk at gennemføre Fysisk sikkerhed i Nuuday',
content_preview: 'Hej Claus Westergaard Kraft. Du skulle have fuldført Nuudays obligatoriske Security Awareness Training. Dette er en påmindelse om, at din deadline er overskredet. Venligst fuldfør træningen hurtigst muligt for at undgå yderligere eskalering.',
author: 'CN=92F670955A004F85901A4883B26C31E9-USER,OU=...,DC=corp,DC=tdc,DC=dk',
timestamp: '2025-12-16T12:00:00Z',
path: 'Inbox',
keywords: ['Security', 'Compliance', 'Mandatory', 'Overdue'],
metadata: {
has_attachments: false
}
}
};
/**
* @swagger
* /api/nodes/{id}/visual:
* get:
* summary: Retrieve a VisualNode representation of a data entity
* description: Fetches raw data by its ID, transforms it into the VisualNode format, and returns it.
* parameters:
* - in: path
* name: id
* required: true
* description: The unique ID of the data entity to retrieve.
* schema:
* type: string
* responses:
* 200:
* description: A VisualNode object.
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/VisualNode'
* 404:
* description: Node not found.
*/
router.get('/:id/visual', (req, res) => {
const nodeId = req.params.id;
// For this prototype, we only have one type of data to transform.
// We'll use a simple mock database lookup.
const rawEmail = mockEmailDatabase[nodeId];
if (rawEmail) {
try {
const visualNode = VisualNodeTransformer.transformEmail(rawEmail);
return res.json(visualNode);
} catch (error) {
console.error("Transformation error:", error);
return res.status(500).json({ error: 'Failed to transform node data.' });
}
} else {
return res.status(404).json({ error: `Node with ID '${nodeId}' not found.` });
}
});
export default router;