Added public endpoints
ADD
src/assets/server/rest/v1/schemas/asset/asset-get-image.json
+{
+ "$id": "asset-get-image",
+ "title": "Get Asset Image Request",
+ "type": "object",
+ "properties": {
+ "ID": {
+ "$ref": "asset#/definitions/id"
+ },
+ "TenantID": {
+ "$ref": "common#/definitions/id"
+ }
+ },
+ "required": [
+ "ID",
+ "TenantID"
+ ]
+}

MODIFY
src/server/rest/v1/router/api/AssetRouter.ts
src/server/rest/v1/router/api/AssetRouter.ts
@@ -23,7 +23,6 @@ export default class AssetRouter {
this.buildRouteGetAssetConsumptions();
this.buildRouteUpdateAsset();
this.buildRouteDeleteAsset();
- this.buildRouteGetAssetImage();
return this.router;
}
@@ -93,11 +92,4 @@ export default class AssetRouter {
await RouterUtils.handleServerAction(AssetService.handleDeleteAsset.bind(this), ServerAction.ASSET_DELETE, req, res, next);
});
}
-
- private 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/server/rest/v1/router/api/CarRouter.ts
src/server/rest/v1/router/api/CarRouter.ts
@@ -16,7 +16,6 @@ export default class CarRouter {
this.buildRouteGetCarCatalogs();
this.buildRouteGetCarCatalog();
this.buildRouteGetCarCatalogImages();
- this.buildRouteGetCarCatalogImage();
this.buildRouteCarCatalogsSynchronize();
this.buildRouteGetCarMakers();
this.buildRouteCreateCar();
@@ -47,13 +46,6 @@ export default class CarRouter {
});
}
- private buildRouteGetCarCatalogImage(): void {
- this.router.get(`/${ServerRoute.REST_CAR_CATALOG_IMAGE}`, async (req: Request, res: Response, next: NextFunction) => {
- req.query.ID = req.params.id;
- await RouterUtils.handleServerAction(CarService.handleGetCarCatalogImage.bind(this), ServerAction.CAR_CATALOG_IMAGE, req, res, next);
- });
- }
-
private buildRouteCarCatalogsSynchronize(): void {
this.router.put(`/${ServerRoute.REST_CAR_CATALOG_SYNCHRONIZE}`, async (req: Request, res: Response, next: NextFunction) => {
await RouterUtils.handleServerAction(CarService.handleSynchronizeCarCatalogs.bind(this), ServerAction.CAR_CATALOG_SYNCHRONIZATION, req, res, next);

MODIFY
src/server/rest/v1/router/api/ChargingStationRouter.ts
src/server/rest/v1/router/api/ChargingStationRouter.ts
@@ -18,7 +18,6 @@ export default class ChargingStationRouter {
this.buildRouteChargingStationsExport();
this.buildRouteChargingStationGetChargingProfiles();
this.buildRouteChargingStationRequestOCPPParameters();
- this.buildRouteChargingStationDownloadFirmware();
this.buildRouteChargingStationDeleteChargingProfile();
this.buildRouteChargingStationUpdateChargingProfile();
this.buildRouteChargingStationCreateChargingProfile();
@@ -226,13 +225,6 @@ export default class ChargingStationRouter {
});
}
- private buildRouteChargingStationDownloadFirmware(): void {
- this.router.get(`/${ServerRoute.REST_CHARGING_STATIONS_DOWNLOAD_FIRMWARE}`, async (req: Request, res: Response, next: NextFunction) => {
- req.query.ID = req.params.id;
- await RouterUtils.handleServerAction(ChargingStationService.handleGetFirmware.bind(this), ServerAction.FIRMWARE_DOWNLOAD, req, res, next);
- });
- }
-
private buildRouteChargingStationCheckSmartCharging(): void {
this.router.get(`/${ServerRoute.REST_CHARGING_STATION_CHECK_SMART_CHARGING_CONNECTION}`, async (req: Request, res: Response, next: NextFunction) => {
await RouterUtils.handleServerAction(ChargingStationService.handleCheckSmartChargingConnection.bind(this), ServerAction.CHECK_SMART_CHARGING_CONNECTION, req, res, next);

MODIFY
src/server/rest/v1/router/api/CompanyRouter.ts
src/server/rest/v1/router/api/CompanyRouter.ts
@@ -18,7 +18,6 @@ export default class CompanyRouter {
this.buildRouteCreateCompany();
this.buildRouteUpdateCompany();
this.buildRouteDeleteCompany();
- this.buildRouteGetCompanyLogo();
return this.router;
}
@@ -54,11 +53,4 @@ export default class CompanyRouter {
await RouterUtils.handleServerAction(CompanyService.handleDeleteCompany.bind(this), ServerAction.COMPANY_DELETE, req, res, next);
});
}
-
- private buildRouteGetCompanyLogo(): void {
- this.router.get(`/${ServerRoute.REST_COMPANY_LOGO}`, async (req: Request, res: Response, next: NextFunction) => {
- req.query.ID = req.params.id;
- await RouterUtils.handleServerAction(CompanyService.handleGetCompanyLogo.bind(this), ServerAction.COMPANY_LOGO, req, res, next);
- });
- }
}

MODIFY
src/server/rest/v1/router/api/SiteAreaRouter.ts
src/server/rest/v1/router/api/SiteAreaRouter.ts
@@ -19,7 +19,6 @@ export default class SiteAreaRouter {
this.buildRouteGetSiteAreaConsumption();
this.buildRouteUpdateSiteArea();
this.buildRouteDeleteSiteArea();
- this.buildRouteGetSiteAreaImage();
this.buildRouteAssignChargingStationsToSiteArea();
this.buildRouteRemoveChargingStationsFromSiteArea();
this.buildRouteAssignAssetsToSiteArea();
@@ -67,13 +66,6 @@ export default class SiteAreaRouter {
});
}
- private buildRouteGetSiteAreaImage(): void {
- this.router.get(`/${ServerRoute.REST_SITE_AREA_IMAGE}`, async (req: Request, res: Response, next: NextFunction) => {
- req.query.ID = req.params.id;
- await RouterUtils.handleServerAction(SiteAreaService.handleGetSiteAreaImage.bind(this), ServerAction.SITE_AREA_IMAGE, req, res, next);
- });
- }
-
private buildRouteAssignChargingStationsToSiteArea(): void {
this.router.put(`/${ServerRoute.REST_SITE_AREA_ASSIGN_CHARGING_STATIONS}`, async (req: Request, res: Response, next: NextFunction) => {
req.body.siteAreaID = req.params.id;

MODIFY
src/server/rest/v1/router/util/UtilRouter.ts
src/server/rest/v1/router/util/UtilRouter.ts
+/* eslint-disable @typescript-eslint/no-misused-promises */
+import { ServerAction, ServerRoute } from '../../../../../types/Server';
import express, { NextFunction, Request, Response } from 'express';
-import { ServerRoute } from '../../../../../types/Server';
+import AssetService from '../../service/AssetService';
+import CarService from '../../service/CarService';
+import ChargingStationService from '../../service/ChargingStationService';
+import CompanyService from '../../service/CompanyService';
+import RouterUtils from '../RouterUtils';
+import SiteAreaService from '../../service/SiteAreaService';
import { StatusCodes } from 'http-status-codes';
export default class UtilRouter {
@@ -12,6 +19,11 @@ export default class UtilRouter {
public buildRoutes(): express.Router {
this.buildRoutePing();
+ this.buildRouteGetCarCatalogImage();
+ this.buildRouteGetAssetImage();
+ this.buildRouteGetCompanyLogo();
+ this.buildRouteGetSiteAreaImage();
+ this.buildRouteChargingStationDownloadFirmware();
return this.router;
}
@@ -21,4 +33,39 @@ export default class UtilRouter {
next();
});
}
+
+ private buildRouteGetCarCatalogImage(): void {
+ this.router.get(`/${ServerRoute.REST_CAR_CATALOG_IMAGE}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.query.ID = req.params.id;
+ await RouterUtils.handleServerAction(CarService.handleGetCarCatalogImage.bind(this), ServerAction.CAR_CATALOG_IMAGE, req, res, next);
+ });
+ }
+
+ private 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);
+ });
+ }
+
+ private buildRouteGetCompanyLogo(): void {
+ this.router.get(`/${ServerRoute.REST_COMPANY_LOGO}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.query.ID = req.params.id;
+ await RouterUtils.handleServerAction(CompanyService.handleGetCompanyLogo.bind(this), ServerAction.COMPANY_LOGO, req, res, next);
+ });
+ }
+
+ private buildRouteGetSiteAreaImage(): void {
+ this.router.get(`/${ServerRoute.REST_SITE_AREA_IMAGE}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.query.ID = req.params.id;
+ await RouterUtils.handleServerAction(SiteAreaService.handleGetSiteAreaImage.bind(this), ServerAction.SITE_AREA_IMAGE, req, res, next);
+ });
+ }
+
+ private buildRouteChargingStationDownloadFirmware(): void {
+ this.router.get(`/${ServerRoute.REST_CHARGING_STATIONS_DOWNLOAD_FIRMWARE}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.query.ID = req.params.id;
+ await RouterUtils.handleServerAction(ChargingStationService.handleGetFirmware.bind(this), ServerAction.FIRMWARE_DOWNLOAD, req, res, next);
+ });
+ }
}

MODIFY
src/server/rest/v1/service/AssetService.ts
src/server/rest/v1/service/AssetService.ts
@@ -21,6 +21,7 @@ import SiteArea from '../../../../types/SiteArea';
import SiteAreaStorage from '../../../../storage/mongodb/SiteAreaStorage';
import { StatusCodes } from 'http-status-codes';
import { TenantComponents } from '../../../../types/Tenant';
+import TenantStorage from '../../../../storage/mongodb/TenantStorage';
import Utils from '../../../../utils/Utils';
import UtilsService from './UtilsService';
import moment from 'moment';
@@ -433,10 +434,12 @@ export default class AssetService {
public static async handleGetAssetImage(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const filteredRequest = AssetValidator.getInstance().validateAssetGetReq(req.query);
- UtilsService.assertIdIsProvided(action, filteredRequest.ID, MODULE_NAME, 'handleGetAssetImage', req.user);
- // Get it
- const assetImage = await AssetStorage.getAssetImage(req.tenant, filteredRequest.ID);
+ const filteredRequest = AssetValidator.getInstance().validateAssetGetImageReq(req.query);
+ // Get the tenant
+ const tenant = await TenantStorage.getTenant(filteredRequest.TenantID);
+ UtilsService.assertObjectExists(action, tenant, 'Tenant does not exist', MODULE_NAME, 'handleGetAssetImage', req.user);
+ // Get the image
+ const assetImage = await AssetStorage.getAssetImage(tenant, filteredRequest.ID);
// Return
if (assetImage?.image) {
let header = 'image';

MODIFY
src/server/rest/v1/validator/AssetValidator.ts
src/server/rest/v1/validator/AssetValidator.ts
-import { HttpAssetCheckConnection, HttpAssetConsumptionRequest, HttpAssetRequest, HttpAssetsRequest } from '../../../../types/requests/HttpAssetRequest';
+import { HttpAssetCheckConnection, HttpAssetConsumptionRequest, HttpAssetImageRequest, HttpAssetRequest, HttpAssetsRequest } from '../../../../types/requests/HttpAssetRequest';
import Asset from '../../../../types/Asset';
import Consumption from '../../../../types/Consumption';
@@ -16,6 +16,7 @@ export default class AssetValidator extends SchemaValidator {
private assetUpdate: Schema;
private assetConsumptionsGet: Schema;
private assetConnectionCheck: Schema;
+ private assetGetImage: Schema;
private constructor() {
super('AssetValidator');
@@ -26,6 +27,7 @@ export default class AssetValidator extends SchemaValidator {
this.assetUpdate = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/asset/asset-update.json`, 'utf8'));
this.assetConsumptionsGet = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/asset/asset-consumptions-get.json`, 'utf8'));
this.assetConnectionCheck = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/asset/asset-connection-check.json`, 'utf8'));
+ this.assetGetImage = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/asset/asset-get-image.json`, 'utf8'));
}
public static getInstance(): AssetValidator {
@@ -62,4 +64,8 @@ export default class AssetValidator extends SchemaValidator {
public validateAssetCheckConnectionReq(data: Record<string, unknown>): HttpAssetCheckConnection {
return this.validate(this.assetConnectionCheck, data);
}
+
+ public validateAssetGetImageReq(data: Record<string, unknown>): HttpAssetImageRequest {
+ return this.validate(this.assetGetImage, data);
+ }
}

MODIFY
test/api/client/utils/CrudApi.ts
test/api/client/utils/CrudApi.ts
@@ -65,14 +65,14 @@ export default class CrudApi {
});
}
- protected buildRestEndpointUrl(urlPatternAsString: ServerRoute, params: { [name: string]: string | number | null } = {}): string {
+ protected buildRestEndpointUrl(urlPatternAsString: ServerRoute, params: { [name: string]: string | number | null } = {}, urlPrefix = 'api'): string {
let resolvedUrlPattern = urlPatternAsString as string;
for (const key in params) {
if (Object.prototype.hasOwnProperty.call(params, key)) {
resolvedUrlPattern = resolvedUrlPattern.replace(`:${key}`, encodeURIComponent(params[key]));
}
}
- return '/v1/api/' + resolvedUrlPattern;
+ return `/v1/${urlPrefix}/${resolvedUrlPattern}`;
}
private buildPaging(paging, queryString): void {

Added public endpoints