diff --git a/measurement.html b/measurement.html
index 6705092..bab56f6 100644
--- a/measurement.html
+++ b/measurement.html
@@ -38,6 +38,7 @@
assetType: { value: "" },
model: { value: "" },
unit: { value: "" },
+ assetTagNumber: { value: "" },
//logger properties
enableLog: { value: false },
diff --git a/measurement.js b/measurement.js
index 31b6f80..f0ed4c7 100644
--- a/measurement.js
+++ b/measurement.js
@@ -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 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
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 });
+ }
+ });
+
};
\ No newline at end of file
diff --git a/src/nodeClass.js b/src/nodeClass.js
index d49657a..b3ac9e6 100644
--- a/src/nodeClass.js
+++ b/src/nodeClass.js
@@ -59,6 +59,7 @@ class nodeClass {
asset: {
uuid: uiConfig.assetUuid, //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,
category: uiConfig.category, //add later to define as the software type
type: uiConfig.assetType,