Added getConsumption/update/delete/getImage endpoints+doc
MODIFY
src/assets/server/rest/v1/docs/e-mobility-oas.json
src/assets/server/rest/v1/docs/e-mobility-oas.json
"$ref": "#/components/responses/ResourceDoesNotExists"
}
}
+ },
+ "put": {
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "description": "Update an Asset",
+ "parameters": [
+ {
+ "$ref": "#/components/parameters/assetID"
+ }
+ ],
+ "requestBody": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/Asset"
+ }
+ }
+ }
+ },
+ "tags": [
+ "Assets"
+ ],
+ "responses": {
+ "200": {
+ "description": "Asset updated successfully",
+ "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"
+ }
+ }
+ },
+ "delete": {
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "description": "Delete an Asset",
+ "parameters": [
+ {
+ "$ref": "#/components/parameters/assetID"
+ }
+ ],
+ "tags": [
+ "Assets"
+ ],
+ "responses": {
+ "200": {
+ "description": "Asset deleted successfully",
+ "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"
+ }
+ }
}
},
"/api/assets/status/in-error": {
}
}
}
+ },
+ "/api/assets/{id}/consumptions": {
+ "get": {
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "description": "Get asset's consumptions",
+ "parameters": [
+ {
+ "$ref": "#/components/parameters/assetID"
+ },
+ {
+ "in": "query",
+ "name": "StartDate",
+ "description": "Consumption Start Date (ISO format)",
+ "required": true,
+ "schema": {
+ "type": "string"
+ }
+ },
+ {
+ "in": "query",
+ "name": "EndDate",
+ "description": "Consumption start Date (ISO format)",
+ "required": true,
+ "schema": {
+ "type": "string"
+ }
+ }
+ ],
+ "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"
+ }
+ }
+ }
+ },
+ "/api/assets/{id}/image": {
+ "get": {
+ "security": [
+ {
+ "bearerAuth": []
+ }
+ ],
+ "description": "Get asset's image",
+ "parameters": [
+ {
+ "$ref": "#/components/parameters/assetID"
+ }
+ ],
+ "tags": [
+ "Assets"
+ ],
+ "responses": {
+ "200": {
+ "description": "Returned asset's image"
+ },
+ "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
@@ -20,11 +20,15 @@ export default class AssetRouter {
this.buildRouteGetAssetsInError();
this.buildRouteCheckAssetConnection();
this.buildRouteGetAssetLastConsumption();
+ this.buildRouteGetAssetConsumptions();
+ this.buildRouteUpdateAsset();
+ this.buildRouteDeleteAsset();
+ this.buildRouteGetAssetImage();
return this.router;
}
protected buildRouteCreateAssetConsumption(): void {
- this.router.post(`/${ServerRoute.REST_ASSET_CONSUMPTION}`, async (req: Request, res: Response, next: NextFunction) => {
+ this.router.post(`/${ServerRoute.REST_ASSET_CONSUMPTIONS}`, async (req: Request, res: Response, next: NextFunction) => {
req.query.assetID = req.params.id;
await RouterUtils.handleServerAction(AssetService.handleCreateAssetConsumption.bind(this), ServerAction.ASSET_CONSUMPTION, req, res, next);
});
@@ -68,4 +72,32 @@ export default class AssetRouter {
await RouterUtils.handleServerAction(AssetService.handleRetrieveConsumption.bind(this), ServerAction.RETRIEVE_ASSET_CONSUMPTION, req, res, next);
});
}
+
+ protected buildRouteGetAssetConsumptions(): void {
+ this.router.get(`/${ServerRoute.REST_ASSET_CONSUMPTIONS}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.query.AssetID = req.params.id;
+ await RouterUtils.handleServerAction(AssetService.handleGetAssetConsumption.bind(this), ServerAction.ASSET_CONSUMPTION, req, res, next);
+ });
+ }
+
+ protected buildRouteUpdateAsset(): void {
+ this.router.put(`/${ServerRoute.REST_ASSET}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.query.ID = req.params.id;
+ await RouterUtils.handleServerAction(AssetService.handleUpdateAsset.bind(this), ServerAction.ASSET_UPDATE, req, res, next);
+ });
+ }
+
+ protected buildRouteDeleteAsset(): void {
+ this.router.delete(`/${ServerRoute.REST_ASSET}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.query.ID = req.params.id;
+ await RouterUtils.handleServerAction(AssetService.handleDeleteAsset.bind(this), ServerAction.ASSET_DELETE, req, res, next);
+ });
+ }
+
+ protected buildRouteGetAssetImage(): void {
+ this.router.get(`/${ServerRoute.REST_ASSET_IMAGE}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.query.ID = req.params.id;
+ await RouterUtils.handleServerAction(AssetService.handleGetAssetImage.bind(this), ServerAction.ASSET_IMAGE, req, res, next);
+ });
+ }
}

MODIFY
src/types/Server.ts
src/types/Server.ts
@@ -528,10 +528,11 @@ 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_ASSET_CONSUMPTIONS = 'assets/:id/consumptions',
+ REST_ASSET_IMAGE = 'assets/:id/image',
REST_PING = 'ping',

MODIFY
test/api/client/AssetApi.ts
test/api/client/AssetApi.ts
@@ -22,11 +22,11 @@ export default class AssetApi extends CrudApi {
}
public async update(data: Asset): Promise<any> {
- return super.update(data, '/client/api/AssetUpdate');
+ return super.update(data, this.buildRestEndpointUrl(ServerRoute.REST_ASSET, { id: data.id }));
}
public async delete(id: string): Promise<any> {
- return super.delete(id, '/client/api/AssetDelete');
+ return super.delete(id, this.buildRestEndpointUrl(ServerRoute.REST_ASSET, { id }));
}
public async readAllInError(params, paging = TestConstants.DEFAULT_PAGING, ordering = TestConstants.DEFAULT_ORDERING): Promise<any> {

Added getConsumption/update/delete/getImage endpoints+doc