Align endpoints:
Registration token
Site Area
Tag
MODIFY
src/server/rest/v1/service/RegistrationTokenService.ts
src/server/rest/v1/service/RegistrationTokenService.ts
@@ -7,6 +7,7 @@ import AppError from '../../../../exception/AppError';
import AuthorizationService from './AuthorizationService';
import Constants from '../../../../utils/Constants';
import Logging from '../../../../utils/Logging';
+import LoggingHelper from '../../../../utils/LoggingHelper';
import RegistrationToken from '../../../../types/RegistrationToken';
import { RegistrationTokenDataResult } from '../../../../types/DataResult';
import RegistrationTokenStorage from '../../../../storage/mongodb/RegistrationTokenStorage';
@@ -20,7 +21,7 @@ import moment from 'moment';
const MODULE_NAME = 'RegistrationTokenService';
export default class RegistrationTokenService {
- static async handleCreateRegistrationToken(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
+ public static async handleCreateRegistrationToken(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
const filteredRequest = RegistrationTokenValidator.getInstance().validateRegistrationTokenCreateReq(req.body);
// Check the Site Area
@@ -50,6 +51,7 @@ export default class RegistrationTokenService {
// Save
registrationToken.id = await RegistrationTokenStorage.saveRegistrationToken(req.tenant, registrationToken);
await Logging.logInfo({
+ ...LoggingHelper.getRegistrationTokenProperties(registrationToken),
tenantID: req.user.tenantID,
user: req.user, module: MODULE_NAME, method: 'handleCreateRegistrationToken',
message: `Registration Token '${registrationToken.description}' has been created successfully`,
@@ -59,7 +61,7 @@ export default class RegistrationTokenService {
next();
}
- static async handleUpdateRegistrationToken(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
+ public static async handleUpdateRegistrationToken(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
const filteredRequest = RegistrationTokenValidator.getInstance().validateRegistrationTokenUpdateReq(req.body);
// Check and Get Registration Token
@@ -80,6 +82,7 @@ export default class RegistrationTokenService {
// Save
await RegistrationTokenStorage.saveRegistrationToken(req.tenant, registrationToken);
await Logging.logInfo({
+ ...LoggingHelper.getRegistrationTokenProperties(registrationToken),
tenantID: req.user.tenantID,
user: req.user, module: MODULE_NAME, method: 'handleUpdateRegistrationToken',
message: `Registration Token '${registrationToken.description}' has been updated successfully`,
@@ -89,7 +92,7 @@ export default class RegistrationTokenService {
next();
}
- static async handleDeleteRegistrationToken(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
+ public static async handleDeleteRegistrationToken(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
const registrationTokenID = RegistrationTokenValidator.getInstance().validateRegistrationTokenGetReq(req.query).ID;
// Check and Get Registration Token
@@ -98,6 +101,7 @@ export default class RegistrationTokenService {
// Delete
await RegistrationTokenStorage.deleteRegistrationToken(req.tenant, registrationToken.id);
await Logging.logInfo({
+ ...LoggingHelper.getRegistrationTokenProperties(registrationToken),
tenantID: req.user.tenantID,
user: req.user,
module: MODULE_NAME, method: 'handleDeleteRegistrationToken',
@@ -108,7 +112,7 @@ export default class RegistrationTokenService {
next();
}
- static async handleRevokeRegistrationToken(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
+ public static async handleRevokeRegistrationToken(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
const registrationTokenID = RegistrationTokenValidator.getInstance().validateRegistrationTokenGetReq(req.query).ID;
// Check and Get Registration Token
@@ -117,6 +121,7 @@ export default class RegistrationTokenService {
if (registrationToken.expirationDate &&
moment(registrationToken.expirationDate).isBefore(new Date())) {
throw new AppError({
+ ...LoggingHelper.getRegistrationTokenProperties(registrationToken),
errorCode: HTTPError.GENERAL_ERROR,
message: 'Cannot revoke a token that has expired',
module: MODULE_NAME, method: 'handleRevokeRegistrationToken',
@@ -130,6 +135,7 @@ export default class RegistrationTokenService {
// Save
await RegistrationTokenStorage.saveRegistrationToken(req.tenant, registrationToken);
await Logging.logInfo({
+ ...LoggingHelper.getRegistrationTokenProperties(registrationToken),
tenantID: req.user.tenantID,
user: req.user,
module: MODULE_NAME, method: 'handleRevokeRegistrationToken',
@@ -140,7 +146,7 @@ export default class RegistrationTokenService {
next();
}
- static async handleGetRegistrationTokens(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
+ public static async handleGetRegistrationTokens(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
const filteredRequest = RegistrationTokenValidator.getInstance().validateRegistrationTokensGetReq(req.query);
// Check dynamic auth
@@ -175,7 +181,7 @@ export default class RegistrationTokenService {
next();
}
- static async handleGetRegistrationToken(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
+ public static async handleGetRegistrationToken(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
const filteredRequest = RegistrationTokenValidator.getInstance().validateRegistrationTokenGetReq(req.query);
// Check and Get Registration Token

MODIFY
src/server/rest/v1/service/SiteAreaService.ts
src/server/rest/v1/service/SiteAreaService.ts
@@ -12,6 +12,7 @@ import ConsumptionStorage from '../../../../storage/mongodb/ConsumptionStorage';
import LockingHelper from '../../../../locking/LockingHelper';
import LockingManager from '../../../../locking/LockingManager';
import Logging from '../../../../utils/Logging';
+import LoggingHelper from '../../../../utils/LoggingHelper';
import OCPPUtils from '../../../ocpp/utils/OCPPUtils';
import { ServerAction } from '../../../../types/Server';
import SiteArea from '../../../../types/SiteArea';
@@ -48,6 +49,7 @@ export default class SiteAreaService {
await SiteAreaStorage.removeAssetsFromSiteArea(req.tenant, filteredRequest.siteAreaID, assets.map((asset) => asset.id));
}
await Logging.logInfo({
+ ...LoggingHelper.getSiteAreaProperties(siteArea),
tenantID: req.user.tenantID,
user: req.user,
module: MODULE_NAME,
@@ -80,6 +82,7 @@ export default class SiteAreaService {
const numberOfConnectedPhase = Utils.getNumberOfConnectedPhases(chargingStation, chargePoint, connector.connectorId);
if (numberOfConnectedPhase !== 1 && action === ServerAction.ADD_CHARGING_STATIONS_TO_SITE_AREA) {
throw new AppError({
+ ...LoggingHelper.getSiteAreaProperties(siteArea),
action: action,
errorCode: HTTPError.THREE_PHASE_CHARGER_ON_SINGLE_PHASE_SITE_AREA,
message: `Error occurred while assigning charging station: '${chargingStation.id}'. Charging Station is not single phased`,
@@ -100,6 +103,7 @@ export default class SiteAreaService {
}
// Log
await Logging.logInfo({
+ ...LoggingHelper.getSiteAreaProperties(siteArea),
tenantID: req.user.tenantID,
user: req.user,
module: MODULE_NAME, method: 'handleAssignChargingStationsToSiteArea',
@@ -124,6 +128,7 @@ export default class SiteAreaService {
await SiteAreaStorage.deleteSiteArea(req.tenant, siteArea.id);
// Log
await Logging.logInfo({
+ ...LoggingHelper.getSiteAreaProperties(siteArea),
tenantID: req.user.tenantID,
user: req.user, module: MODULE_NAME, method: 'handleDeleteSiteArea',
message: `Site Area '${siteArea.name}' has been deleted successfully`,
@@ -296,6 +301,7 @@ export default class SiteAreaService {
// Save
siteArea.id = await SiteAreaStorage.saveSiteArea(req.tenant, siteArea, true);
await Logging.logInfo({
+ ...LoggingHelper.getSiteAreaProperties(siteArea),
tenantID: req.user.tenantID,
user: req.user, module: MODULE_NAME, method: 'handleCreateSiteArea',
message: `Site Area '${siteArea.name}' has been created successfully`,
@@ -337,6 +343,7 @@ export default class SiteAreaService {
const numberOfPhases = Utils.getNumberOfConnectedPhases(chargingStation, null, connector.connectorId);
if (numberOfPhases !== 1) {
throw new AppError({
+ ...LoggingHelper.getSiteAreaProperties(siteArea),
action: action,
errorCode: HTTPError.THREE_PHASE_CHARGER_ON_SINGLE_PHASE_SITE_AREA,
message: `Error occurred while updating SiteArea.'${chargingStation.id}' is not single phased`,
@@ -383,6 +390,7 @@ export default class SiteAreaService {
}
} catch (error) {
await Logging.logError({
+ ...LoggingHelper.getSiteAreaProperties(siteArea),
tenantID: req.user.tenantID,
module: MODULE_NAME, method: 'handleUpdateSiteArea',
action: action,
@@ -397,6 +405,7 @@ export default class SiteAreaService {
}, Constants.DELAY_SMART_CHARGING_EXECUTION_MILLIS);
}
await Logging.logInfo({
+ ...LoggingHelper.getSiteAreaProperties(siteArea),
tenantID: req.user.tenantID,
user: req.user, module: MODULE_NAME, method: 'handleUpdateSiteArea',
message: `Site Area '${siteArea.name}' has been updated successfully`,
@@ -405,6 +414,7 @@ export default class SiteAreaService {
});
if (actionsResponse && actionsResponse.inError > 0) {
throw new AppError({
+ ...LoggingHelper.getSiteAreaProperties(siteArea),
action: action,
errorCode: HTTPError.CLEAR_CHARGING_PROFILE_NOT_SUCCESSFUL,
message: 'Error occurred while clearing Charging Profiles for Site Area',

MODIFY
src/server/rest/v1/service/SiteService.ts
src/server/rest/v1/service/SiteService.ts
@@ -364,6 +364,7 @@ export default class SiteService {
}, Constants.DB_PARAMS_SINGLE_RECORD, ['id']);
if (publicChargingStations.count > 0) {
throw new AppError({
+ ...LoggingHelper.getSiteProperties(site),
errorCode: HTTPError.FEATURE_NOT_SUPPORTED_ERROR,
message: `Cannot set site ${site.name} to private as charging station ${publicChargingStations.result[0].id} under site is public`,
module: MODULE_NAME, method: 'handleUpdateSite',

MODIFY
src/server/rest/v1/service/TagService.ts
src/server/rest/v1/service/TagService.ts
@@ -21,6 +21,7 @@ import JSONStream from 'JSONStream';
import LockingHelper from '../../../../locking/LockingHelper';
import LockingManager from '../../../../locking/LockingManager';
import Logging from '../../../../utils/Logging';
+import LoggingHelper from '../../../../utils/LoggingHelper';
import OCPIClientFactory from '../../../../client/ocpi/OCPIClientFactory';
import { OCPIRole } from '../../../../types/ocpi/OCPIRole';
import { OCPITokenWhitelist } from '../../../../types/ocpi/OCPIToken';
@@ -137,6 +138,7 @@ export default class TagService {
let tag = await TagStorage.getTag(req.tenant, filteredRequest.id.toUpperCase());
if (tag) {
throw new AppError({
+ ...LoggingHelper.getTagProperties(tag),
errorCode: HTTPError.TAG_ALREADY_EXIST_ERROR,
message: `Tag with ID '${filteredRequest.id}' already exists`,
module: MODULE_NAME, method: 'handleCreateTag',
@@ -148,6 +150,7 @@ export default class TagService {
tag = await TagStorage.getTagByVisualID(req.tenant, filteredRequest.visualID);
if (tag) {
throw new AppError({
+ ...LoggingHelper.getTagProperties(tag),
errorCode: HTTPError.TAG_VISUAL_ID_ALREADY_EXIST_ERROR,
message: `Tag with visual ID '${filteredRequest.visualID}' already exists`,
module: MODULE_NAME, method: 'handleCreateTag',
@@ -191,6 +194,7 @@ export default class TagService {
// OCPI
await TagService.updateTagOCPI(action, req.tenant, req.user, newTag);
await Logging.logInfo({
+ ...LoggingHelper.getTagProperties(newTag),
tenantID: req.user.tenantID,
action: action,
user: req.user,
@@ -210,6 +214,7 @@ export default class TagService {
// Check Tag with Visual ID
if (!tag) {
throw new AppError({
+ ...LoggingHelper.getTagProperties(tag),
errorCode: HTTPError.TAG_VISUAL_ID_DOES_NOT_MATCH_TAG_ERROR,
message: `Tag with visual ID '${filteredRequest.visualID}' does not match any badge`,
module: MODULE_NAME, method: 'handleAssignTag',
@@ -220,6 +225,7 @@ export default class TagService {
// Check if tag is active
if (!tag.active) {
throw new AppError({
+ ...LoggingHelper.getTagProperties(tag),
errorCode: HTTPError.TAG_INACTIVE,
message: `Tag with visual ID '${filteredRequest.visualID}' is not active and cannot be assigned`,
module: MODULE_NAME, method: 'handleAssignTag',
@@ -229,6 +235,7 @@ export default class TagService {
}
if (tag.user) {
throw new AppError({
+ ...LoggingHelper.getTagProperties(tag),
errorCode: HTTPError.TAG_ALREADY_EXIST_ERROR,
message: `Tag with ID '${filteredRequest.id}' already exists and assigned to another user`,
module: MODULE_NAME, method: 'handleAssignTag',
@@ -263,6 +270,7 @@ export default class TagService {
// OCPI
await TagService.updateTagOCPI(action, req.tenant, req.user, tag);
await Logging.logInfo({
+ ...LoggingHelper.getTagProperties(tag),
tenantID: req.user.tenantID,
action: action,
user: req.user, actionOnUser: user,
@@ -304,6 +312,7 @@ export default class TagService {
await TagStorage.saveTag(req.tenant, tag);
await TagService.updateTagOCPI(action, req.tenant, req.user, tag);
await Logging.logInfo({
+ ...LoggingHelper.getTagProperties(tag),
tenantID: req.user.tenantID,
action: action,
module: MODULE_NAME, method: 'handleUpdateTagByVisualID',
@@ -331,6 +340,7 @@ export default class TagService {
const tagVisualID = await TagStorage.getTagByVisualID(req.tenant, filteredRequest.visualID);
if (tagVisualID) {
throw new AppError({
+ ...LoggingHelper.getTagProperties(tag),
errorCode: HTTPError.TAG_VISUAL_ID_ALREADY_EXIST_ERROR,
message: `Tag with Visual ID '${filteredRequest.id}' already exists`,
module: MODULE_NAME, method: 'handleUpdateTag',
@@ -379,6 +389,7 @@ export default class TagService {
// OCPI
await TagService.updateTagOCPI(action, req.tenant, req.user, tag);
await Logging.logInfo({
+ ...LoggingHelper.getTagProperties(tag),
tenantID: req.user.tenantID,
action: action,
module: MODULE_NAME, method: 'handleUpdateTag',

MODIFY
src/utils/LoggingHelper.ts
src/utils/LoggingHelper.ts
import Asset from '../types/Asset';
import { Car } from '../types/Car';
import ChargingStation from '../types/ChargingStation';
+import RegistrationToken from '../types/RegistrationToken';
import Site from '../types/Site';
import SiteArea from '../types/SiteArea';
+import Tag from '../types/Tag';
import Transaction from '../types/Transaction';
import User from '../types/User';
@@ -55,4 +57,19 @@ export default class LoggingHelper {
carCatalogID: car.carCatalogID
};
}
+
+ public static getRegistrationTokenProperties(registrationToken: RegistrationToken): { registrationTokenID: string; siteAreaID: string } {
+ return {
+ registrationTokenID: registrationToken.id,
+ siteAreaID: registrationToken.siteAreaID
+ };
+ }
+
+ public static getTagProperties(tag: Tag): { tagID: string; userID: string, visualID: string } {
+ return {
+ tagID: tag.id,
+ userID: tag.userID,
+ visualID: tag.visualID
+ };
+ }
}

Align endpoints:

- Registration token
- Site Area
- Tag