Added getInError / Retrieve last consumption / checkConnection assets endpoint
MODIFY
src/assets/server/rest/v1/docs/e-mobility-oas.json
src/assets/server/rest/v1/docs/e-mobility-oas.json
"schema": {
"type": "boolean"
}
+ },
+ {
+ "$ref": "#/components/parameters/Limit"
+ },
+ {
+ "$ref": "#/components/parameters/Skip"
+ },
+ {
+ "$ref": "#/components/parameters/SortFields"
+ },
+ {
+ "$ref": "#/components/parameters/OnlyRecordCount"
+ },
+ {
+ "$ref": "#/components/parameters/ProjectFields"
}
],
"tags": [
"parameters": [
{
"$ref": "#/components/parameters/assetID"
+ },
+ {
+ "$ref": "#/components/parameters/WithSiteArea"
}
],
"tags": [
}
}
}
+ },
+ "/api/assets/status/in-error": {
+ "get": {
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "description": "Get assets in error list",
+ "parameters": [
+ {
+ "$ref": "#/components/parameters/Search"
+ },
+ {
+ "$ref": "#/components/parameters/Issuer"
+ },
+ {
+ "$ref": "#/components/parameters/SiteAreaIDs"
+ },
+ {
+ "$ref": "#/components/parameters/SiteIDs"
+ },
+ {
+ "$ref": "#/components/parameters/WithSiteArea"
+ },
+ {
+ "in": "query",
+ "name": "ErrorType",
+ "description": "Pipe separated asset error types (missing_site_area)",
+ "schema": {
+ "type": "string"
+ }
+ },
+ {
+ "$ref": "#/components/parameters/Limit"
+ },
+ {
+ "$ref": "#/components/parameters/Skip"
+ },
+ {
+ "$ref": "#/components/parameters/SortFields"
+ },
+ {
+ "$ref": "#/components/parameters/OnlyRecordCount"
+ },
+ {
+ "$ref": "#/components/parameters/ProjectFields"
+ }
+ ],
+ "tags": [
+ "Assets"
+ ],
+ "responses": {
+ "200": {
+ "description": "Return assets in error list",
+ "content": {
+ "application/json": {
+ "example": {
+ "count": 1,
+ "result": [
+ {
+ "name": "###",
+ "errorCode": "missing_site_area",
+ "id": "###"
+ }
+ ]
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#/components/responses/UnauthorizedError"
+ },
+ "403": {
+ "$ref": "#/components/responses/ForbiddenError"
+ },
+ "500": {
+ "$ref": "#/components/responses/BackendError"
+ }
+ }
+ }
+ },
+ "/api/assets/{id}/connection/check": {
+ "get": {
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "description": "Check the asset connection",
+ "parameters": [
+ {
+ "$ref": "#/components/parameters/assetID"
+ }
+ ],
+ "tags": [
+ "Assets"
+ ],
+ "responses": {
+ "200": {
+ "description": "Return asset connection status",
+ "content": {
+ "application/json": {
+ "example": {
+ "status": "Success",
+ "connectionIsValid": true
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#/components/responses/UnauthorizedError"
+ },
+ "403": {
+ "$ref": "#/components/responses/ForbiddenError"
+ },
+ "500": {
+ "$ref": "#/components/responses/BackendError"
+ },
+ "550": {
+ "$ref": "#/components/responses/ResourceDoesNotExists"
+ }
+ }
+ }
+ },
+ "/api/assets/{id}/connector/consumption/retrieve-last": {
+ "get": {
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "description": "Retrieve the asset last consumption",
+ "parameters": [
+ {
+ "$ref": "#/components/parameters/assetID"
+ }
+ ],
+ "tags": [
+ "Assets"
+ ],
+ "responses": {
+ "200": {
+ "description": "Asset's last consumption retrieved",
+ "content": {
+ "application/json": {
+ "example": {
+ "status": "Success"
+ }
+ }
+ }
+ },
+ "401": {
+ "$ref": "#/components/responses/UnauthorizedError"
+ },
+ "403": {
+ "$ref": "#/components/responses/ForbiddenError"
+ },
+ "500": {
+ "$ref": "#/components/responses/BackendError"
+ },
+ "550": {
+ "$ref": "#/components/responses/ResourceDoesNotExists"
+ }
+ }
+ }
}
},
"components": {

MODIFY
src/server/rest/v1/router/api/AssetRouter.ts
src/server/rest/v1/router/api/AssetRouter.ts
@@ -17,6 +17,9 @@ export default class AssetRouter {
this.buildRouteCreateAsset();
this.buildRouteGetAssets();
this.buildRouteGetAsset();
+ this.buildRouteGetAssetsInError();
+ this.buildRouteCheckAssetConnection();
+ this.buildRouteGetAssetLastConsumption();
return this.router;
}
@@ -45,4 +48,24 @@ export default class AssetRouter {
await RouterUtils.handleServerAction(AssetService.handleGetAsset.bind(this), ServerAction.ASSET, req, res, next);
});
}
+
+ protected buildRouteGetAssetsInError(): void {
+ this.router.get(`/${ServerRoute.REST_ASSETS_IN_ERROR}`, async (req: Request, res: Response, next: NextFunction) => {
+ await RouterUtils.handleServerAction(AssetService.handleGetAssetsInError.bind(this), ServerAction.ASSETS_IN_ERROR, req, res, next);
+ });
+ }
+
+ protected buildRouteCheckAssetConnection(): void {
+ this.router.get(`/${ServerRoute.REST_ASSET_CHECK_CONNECTION}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.query.ID = req.params.id;
+ await RouterUtils.handleServerAction(AssetService.handleCheckAssetConnection.bind(this), ServerAction.CHECK_ASSET_CONNECTION, req, res, next);
+ });
+ }
+
+ protected buildRouteGetAssetLastConsumption(): void {
+ this.router.get(`/${ServerRoute.REST_ASSET_RETRIEVE_CONSUMPTION}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.query.ID = req.params.id;
+ await RouterUtils.handleServerAction(AssetService.handleRetrieveConsumption.bind(this), ServerAction.RETRIEVE_ASSET_CONSUMPTION, req, res, next);
+ });
+ }
}

MODIFY
src/types/Server.ts
src/types/Server.ts
@@ -529,6 +529,9 @@ export enum ServerRoute {
REST_ASSETS = 'assets',
REST_ASSET = 'assets/:id',
REST_ASSET_CONSUMPTION = 'assets/:id/consumption',
+ REST_ASSETS_IN_ERROR = 'assets/status/in-error',
+ REST_ASSET_CHECK_CONNECTION = 'assets/:id/connector/connection/check',
+ REST_ASSET_RETRIEVE_CONSUMPTION = 'assets/:id/connector/consumption/retrieve-last',
REST_PING = 'ping',

MODIFY
test/api/AssetTest.ts
test/api/AssetTest.ts
@@ -8,6 +8,7 @@ import ContextProvider from './context/ContextProvider';
import Factory from '../factories/Factory';
import Site from '../../src/types/Site';
import SiteArea from '../../src/types/SiteArea';
+import { StatusCodes } from 'http-status-codes';
import TenantContext from './context/TenantContext';
import chaiSubset from 'chai-subset';
@@ -205,6 +206,39 @@ describe('Asset', function() {
testData.newAsset
);
});
+
+ it('Should be able to find assets in error', async () => {
+ // Create a new Site Area
+ const newSiteArea = await testData.userService.createEntity(
+ testData.userService.siteAreaApi,
+ Factory.siteArea.build({
+ siteID: testData.newSite.id
+ })
+ );
+ testData.createdSiteAreas.push(newSiteArea);
+ expect(newSiteArea).to.not.be.null;
+
+ // Create a new asset
+ const newAsset = await testData.userService.createEntity(
+ testData.userService.assetApi,
+ Factory.asset.build({
+ siteAreaID: newSiteArea.id,
+ assetType: 'PR'
+ })
+ );
+ testData.createdAssets.push(newAsset);
+
+ // Delete the site area
+ await testData.userService.deleteEntity(
+ testData.userService.siteAreaApi,
+ newSiteArea
+ );
+
+ // Read all in error
+ const response = await testData.userService.assetApi.readAllInError({ });
+ expect(response.status).to.be.eq(StatusCodes.OK);
+ expect(response.data.count).to.be.eq(1);
+ });
});
});
});

MODIFY
test/api/client/AssetApi.ts
test/api/client/AssetApi.ts
@@ -28,4 +28,8 @@ export default class AssetApi extends CrudApi {
public async delete(id: string): Promise<any> {
return super.delete(id, '/client/api/AssetDelete');
}
+
+ public async readAllInError(params, paging = TestConstants.DEFAULT_PAGING, ordering = TestConstants.DEFAULT_ORDERING): Promise<any> {
+ return super.readAll(params, paging, ordering, this.buildRestEndpointUrl(ServerRoute.REST_ASSETS_IN_ERROR));
+ }
}

Added getInError / Retrieve last consumption / checkConnection assets endpoint