Save dynamic asset connections data
MODIFY
src/server/rest/service/AssetService.ts
src/server/rest/service/AssetService.ts
@@ -243,7 +243,7 @@ export default class AssetService {
withNoSiteArea: filteredRequest.WithNoSiteArea
},
{ limit: filteredRequest.Limit, skip: filteredRequest.Skip, sort: filteredRequest.Sort, onlyRecordCount: filteredRequest.OnlyRecordCount },
- [ 'id', 'name', 'siteAreaID', 'siteArea.id', 'siteArea.name', 'siteArea.siteID', 'assetType', 'coordinates']
+ [ 'id', 'name', 'siteAreaID', 'siteArea.id', 'siteArea.name', 'siteArea.siteID', 'assetType', 'coordinates', 'dynamicAsset', 'assetConnectionID', 'meterID']
);
// Filter
AssetSecurity.filterAssetsResponse(assets, req.user);
@@ -336,6 +336,9 @@ export default class AssetService {
asset.assetType = filteredRequest.assetType;
asset.coordinates = filteredRequest.coordinates;
asset.image = filteredRequest.image;
+ asset.dynamicAsset = filteredRequest.dynamicAsset;
+ asset.connectionID = filteredRequest.connectionID;
+ asset.meterID = filteredRequest.meterID;
asset.lastChangedBy = { 'id': req.user.id };
asset.lastChangedOn = new Date();
// Update Asset

MODIFY
src/server/rest/service/security/AssetSecurity.ts
src/server/rest/service/security/AssetSecurity.ts
@@ -3,7 +3,6 @@ import Authorizations from '../../../../authorization/Authorizations';
import Asset from '../../../../types/Asset';
import { DataResult } from '../../../../types/DataResult';
import { HttpAssetRequest, HttpAssetsRequest } from '../../../../types/requests/HttpAssetRequest';
-import { AssetConnectionSetting } from '../../../../types/Setting';
import UserToken from '../../../../types/UserToken';
import SiteAreaSecurity from './SiteAreaSecurity';
import UtilsSecurity from './UtilsSecurity';
@@ -52,12 +51,17 @@ export default class AssetSecurity {
filteredRequest.siteAreaID = sanitize(request.siteAreaID),
filteredRequest.assetType = sanitize(request.assetType),
filteredRequest.image = request.image;
+ filteredRequest.dynamicAsset = UtilsSecurity.filterBoolean(request.dynamicAsset);
if (request.coordinates && request.coordinates.length === 2) {
filteredRequest.coordinates = [
sanitize(request.coordinates[0]),
sanitize(request.coordinates[1])
];
}
+ if (request.dynamicAsset) {
+ filteredRequest.connectionID = sanitize(request.connectionID);
+ filteredRequest.meterID = sanitize(request.meterID);
+ }
return filteredRequest;
}
@@ -81,6 +85,9 @@ export default class AssetSecurity {
filteredAsset.assetType = asset.assetType;
filteredAsset.coordinates = asset.coordinates;
filteredAsset.image = asset.image;
+ filteredAsset.dynamicAsset = asset.dynamicAsset;
+ filteredAsset.connectionID = asset.connectionID;
+ filteredAsset.meterID = asset.meterID;
if (asset.siteArea) {
filteredAsset.siteArea = SiteAreaSecurity.filterSiteAreaResponse(asset.siteArea, loggedUser);
}

MODIFY
src/storage/mongodb/AssetStorage.ts
src/storage/mongodb/AssetStorage.ts
@@ -62,14 +62,16 @@ export default class AssetStorage {
// Check Tenant
await Utils.checkTenant(tenantID);
// Set
- const assetMDB: any = {
- _id: assetToSave.id ? Utils.convertToObjectID(assetToSave.id) : new ObjectID(),
- name: assetToSave.name,
- siteAreaID: Utils.convertToObjectID(assetToSave.siteAreaID),
- coordinates: assetToSave.coordinates,
- assetType: assetToSave.assetType,
- issuer: Utils.convertToBoolean(assetToSave.issuer),
- };
+ const assetMDB: any = {};
+ assetMDB._id = assetToSave.id ? Utils.convertToObjectID(assetToSave.id) : new ObjectID();
+ assetMDB.name = assetToSave.name;
+ assetMDB.siteAreaID = Utils.convertToObjectID(assetToSave.siteAreaID);
+ assetMDB.coordinates = assetToSave.coordinates;
+ assetMDB.assetType = assetToSave.assetType;
+ assetMDB.dynamicAsset = assetToSave.dynamicAsset;
+ assetMDB.issuer = Utils.convertToBoolean(assetToSave.issuer);
+ assetMDB.connectionID = assetToSave.connectionID;
+ assetMDB.meterID = assetToSave.meterID;
// Add Last Changed/Created props
DatabaseUtils.addLastChangedCreatedProps(assetMDB, assetToSave);
// Modify

MODIFY
src/types/Asset.ts
src/types/Asset.ts
@@ -10,4 +10,7 @@ export default interface Asset extends CreatedUpdatedProps {
coordinates: number[];
issuer: boolean;
image?: string;
+ dynamicAsset: boolean;
+ connectionID?: string;
+ meterID?: string;
}

MODIFY
src/utils/Utils.ts
src/utils/Utils.ts
@@ -1436,6 +1436,28 @@ export default class Utils {
user: req.user.id
});
}
+ if (asset.dynamicAsset) {
+ if (!asset.connectionID) {
+ throw new AppError({
+ source: Constants.CENTRAL_SERVER,
+ errorCode: HTTPError.GENERAL_ERROR,
+ message: 'Asset connection is mandatory',
+ module: MODULE_NAME,
+ method: 'checkIfAssetValid',
+ user: req.user.id
+ });
+ }
+ if (!asset.meterID) {
+ throw new AppError({
+ source: Constants.CENTRAL_SERVER,
+ errorCode: HTTPError.GENERAL_ERROR,
+ message: 'Asset meter ID is mandatory',
+ module: MODULE_NAME,
+ method: 'checkIfAssetValid',
+ user: req.user.id
+ });
+ }
+ }
}
public static async checkIfUserTagsAreValid(user: User, tags: Tag[], req: Request): Promise<void> {

Save dynamic asset connections data