Removed Asset security class
MODIFY
src/assets/server/rest/v1/schemas/asset/asset-get-consumptions.json
src/assets/server/rest/v1/schemas/asset/asset-get-consumptions.json
"title": "Get Asset Consumptions by ID Request",
"type": "object",
"properties": {
- "ID": {
+ "AssetID": {
"$ref": "asset.json#/definitions/id"
},
"StartDate": {
}
},
"required": [
- "ID",
+ "AssetID",
"StartDate",
"EndDate"
]

MODIFY
src/server/rest/v1/router/api/AssetRouter.ts
src/server/rest/v1/router/api/AssetRouter.ts
@@ -82,7 +82,7 @@ export default class AssetRouter {
protected buildRouteUpdateAsset(): void {
this.router.put(`/${ServerRoute.REST_ASSET}`, async (req: Request, res: Response, next: NextFunction) => {
- req.query.ID = req.params.id;
+ req.body.id = req.params.id;
await RouterUtils.handleServerAction(AssetService.handleUpdateAsset.bind(this), ServerAction.ASSET_UPDATE, req, res, next);
});
}

MODIFY
src/server/rest/v1/service/AssetService.ts
src/server/rest/v1/service/AssetService.ts
@@ -7,7 +7,6 @@ import AppError from '../../../../exception/AppError';
import Asset from '../../../../types/Asset';
import AssetFactory from '../../../../integration/asset/AssetFactory';
import { AssetInErrorType } from '../../../../types/InError';
-import AssetSecurity from './security/AssetSecurity';
import AssetStorage from '../../../../storage/mongodb/AssetStorage';
import AssetValidator from '../validator/AssetValidator';
import AuthorizationService from './AuthorizationService';
@@ -356,7 +355,7 @@ export default class AssetService {
},
{ limit: filteredRequest.Limit,
skip: filteredRequest.Skip,
- sort: filteredRequest.SortFields,
+ sort: UtilsService.httpSortFieldsToMongoDB(filteredRequest.SortFields),
onlyRecordCount: filteredRequest.OnlyRecordCount
},
[ 'id', 'name', 'errorCodeDetails', 'errorCode' ]

DELETE
src/server/rest/v1/service/security/AssetSecurity.ts
-import { HttpAssetConsumptionRequest, HttpAssetImageRequest, HttpAssetRequest, HttpAssetsRequest } from '../../../../../types/requests/HttpAssetRequest';
-
-import Asset from '../../../../../types/Asset';
-import Utils from '../../../../../utils/Utils';
-import UtilsSecurity from './UtilsSecurity';
-import sanitize from 'mongo-sanitize';
-
-export default class AssetSecurity {
-
- public static filterAssetRequestByID(request: any): string {
- return sanitize(request.ID);
- }
-
- public static filterAssetImageRequest(request: any): HttpAssetImageRequest {
- return {
- ID: sanitize(request.ID),
- TenantID: sanitize(request.TenantID),
- };
- }
-
- public static filterAssetRequest(request: any): HttpAssetRequest {
- return {
- ID: sanitize(request.ID),
- WithSiteArea: UtilsSecurity.filterBoolean(request.WithSiteArea)
- } as HttpAssetRequest;
- }
-
- public static filterAssetsRequest(request: any): HttpAssetsRequest {
- const filteredRequest: HttpAssetsRequest = {
- Search: sanitize(request.Search),
- SiteAreaID: sanitize(request.SiteAreaID),
- SiteID: sanitize(request.SiteID),
- WithSiteArea: UtilsSecurity.filterBoolean(request.WithSiteArea),
- WithNoSiteArea: UtilsSecurity.filterBoolean(request.WithNoSiteArea),
- DynamicOnly: UtilsSecurity.filterBoolean(request.DynamicOnly),
- ErrorType: sanitize(request.ErrorType)
- } as HttpAssetsRequest;
- if (Utils.objectHasProperty(request, 'Issuer')) {
- filteredRequest.Issuer = UtilsSecurity.filterBoolean(request.Issuer);
- }
- UtilsSecurity.filterSkipAndLimit(request, filteredRequest);
- UtilsSecurity.filterSort(request, filteredRequest);
- return filteredRequest;
- }
-
- static filterAssetUpdateRequest(request: any): Partial<Asset> {
- const filteredRequest = AssetSecurity._filterAssetRequest(request);
- return {
- id: sanitize(request.id),
- ...filteredRequest
- };
- }
-
- public static filterAssetCreateRequest(request: any): Partial<Asset> {
- return AssetSecurity._filterAssetRequest(request);
- }
-
- public static filterAssetConsumptionRequest(request: any): HttpAssetConsumptionRequest {
- return {
- AssetID: sanitize(request.AssetID),
- StartDate: sanitize(request.StartDate),
- EndDate: sanitize(request.EndDate)
- };
- }
-
- private static _filterAssetRequest(request: any): Partial<Asset> {
- const filteredRequest: Partial<Asset> = {};
- filteredRequest.name = sanitize(request.name),
- filteredRequest.siteAreaID = sanitize(request.siteAreaID),
- filteredRequest.assetType = sanitize(request.assetType),
- filteredRequest.excludeFromSmartCharging = UtilsSecurity.filterBoolean(sanitize(request.excludeFromSmartCharging));
- filteredRequest.variationThresholdPercent = sanitize(request.variationThresholdPercent),
- filteredRequest.fluctuationPercent = sanitize(request.fluctuationPercent),
- filteredRequest.staticValueWatt = sanitize(request.staticValueWatt),
- filteredRequest.image = request.image;
- filteredRequest.dynamicAsset = UtilsSecurity.filterBoolean(request.dynamicAsset);
- filteredRequest.usesPushAPI = UtilsSecurity.filterBoolean(request.usesPushAPI);
- if (Utils.objectHasProperty(request, 'coordinates') && !Utils.isEmptyArray(request.coordinates) && request.coordinates.length === 2) {
- filteredRequest.coordinates = [
- sanitize(request.coordinates[0]),
- sanitize(request.coordinates[1])
- ];
- }
- if (Utils.objectHasProperty(request, 'dynamicAsset')) {
- filteredRequest.connectionID = sanitize(request.connectionID);
- filteredRequest.meterID = sanitize(request.meterID);
- }
- return filteredRequest;
- }
-}

Removed Asset security class