updates
This commit is contained in:
@@ -38,6 +38,7 @@
|
||||
assetType: { value: "" },
|
||||
model: { value: "" },
|
||||
unit: { value: "" },
|
||||
assetTagNumber: { value: "" },
|
||||
|
||||
//logger properties
|
||||
enableLog: { value: false },
|
||||
|
||||
@@ -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 });
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user