This commit is contained in:
znetsixe
2026-01-29 09:16:33 +01:00
parent 339ae6bdde
commit 671eb5f5fb
3 changed files with 26 additions and 1 deletions

View File

@@ -38,6 +38,7 @@
assetType: { value: "" }, assetType: { value: "" },
model: { value: "" }, model: { value: "" },
unit: { value: "" }, unit: { value: "" },
assetTagNumber: { value: "" },
//logger properties //logger properties
enableLog: { value: false }, enableLog: { value: false },

View File

@@ -1,6 +1,7 @@
const nameOfNode = 'measurement'; // this is the name of the node, it should match the file name and the node type in Node-RED const nameOfNode = 'measurement'; // this is the name of the node, it should match the file name and the node type in Node-RED
const nodeClass = require('./src/nodeClass.js'); // this is the specific node class const nodeClass = require('./src/nodeClass.js'); // this is the specific node class
const { MenuManager, configManager } = require('generalFunctions'); const { MenuManager, configManager, assetApiConfig } = require('generalFunctions');
const assetUtils = require('generalFunctions/assetUtils');
// This is the main entry point for the Node-RED node, it will register the node and setup the endpoints // This is the main entry point for the Node-RED node, it will register the node and setup the endpoints
module.exports = function(RED) { module.exports = function(RED) {
@@ -37,4 +38,26 @@ module.exports = function(RED) {
} }
}); });
RED.httpAdmin.post(`/${nameOfNode}/asset-reg`, async (req, res) => {
const body = req.body || {};
const assetPayload = body.asset;
if (!assetPayload) {
return res.status(400).json({ success: false, message: 'Missing asset payload' });
}
try {
const nodeConfig = cfgMgr.getConfig(nameOfNode);
const registrationDefaults = (nodeConfig && nodeConfig.assetRegistration) || {};
const result = await assetUtils.syncAsset({
assetSelection: assetPayload,
registrationDefaults,
apiConfig: assetApiConfig,
nodeContext: { id: body.nodeId, name: body.nodeName }
});
res.json({ success: result.success, data: result.data, message: result.message });
} catch (error) {
console.error(`[${nameOfNode}] asset-reg error`, error);
res.status(500).json({ success: false, message: error.message });
}
});
}; };

View File

@@ -59,6 +59,7 @@ class nodeClass {
asset: { asset: {
uuid: uiConfig.assetUuid, //need to add this later to the asset model uuid: uiConfig.assetUuid, //need to add this later to the asset model
tagCode: uiConfig.assetTagCode, //need to add this later to the asset model tagCode: uiConfig.assetTagCode, //need to add this later to the asset model
tagNumber: uiConfig.assetTagNumber,
supplier: uiConfig.supplier, supplier: uiConfig.supplier,
category: uiConfig.category, //add later to define as the software type category: uiConfig.category, //add later to define as the software type
type: uiConfig.assetType, type: uiConfig.assetType,