Add rebuild of consumptions + fixed typos
MODIFY
src/migration/tasks/RecomputeAllTransactionsConsumptionsTask.ts
src/migration/tasks/RecomputeAllTransactionsConsumptionsTask.ts
@@ -44,7 +44,7 @@ export default class RecomputeAllTransactionsConsumptionsTask extends MigrationT
try {
// Recompute consumption
const timeFrom = new Date().getTime();
- const nbrOfConsumptions = await OCPPUtils.recomputeTransactionConsumptions(tenant.id, transactionMDB._id);
+ const nbrOfConsumptions = await OCPPUtils.rebuildTransactionConsumptions(tenant.id, transactionMDB._id);
const durationSecs = Math.trunc((new Date().getTime() - timeFrom) / 1000);
consumptionsUpdated.inSuccess++;
if (nbrOfConsumptions > 0) {

MODIFY
src/server/ocpp/services/OCPPService.ts
src/server/ocpp/services/OCPPService.ts
@@ -1111,10 +1111,10 @@ export default class OCPPService {
if (!transaction.transactionEndReceived) {
// First time: Clear all values
transaction.currentInstantWatts = 0;
- transaction.currentInstanWattsL1 = 0;
- transaction.currentInstanWattsL2 = 0;
- transaction.currentInstanWattsL3 = 0;
- transaction.currentInstanWattsDC = 0;
+ transaction.currentInstantWattsL1 = 0;
+ transaction.currentInstantWattsL2 = 0;
+ transaction.currentInstantWattsL3 = 0;
+ transaction.currentInstantWattsDC = 0;
transaction.currentInstantVoltage = 0;
transaction.currentInstantVoltageL1 = 0;
transaction.currentInstantVoltageL2 = 0;
@@ -1194,18 +1194,18 @@ export default class OCPPService {
// AC Charging Station
switch (currentType) {
case CurrentType.DC:
- transaction.currentInstanWattsDC = powerInMeterValueWatts;
+ transaction.currentInstantWattsDC = powerInMeterValueWatts;
break;
case CurrentType.AC:
switch (meterValue.attribute.phase) {
case OCPPPhase.L1:
- transaction.currentInstanWattsL1 = powerInMeterValueWatts;
+ transaction.currentInstantWattsL1 = powerInMeterValueWatts;
break;
case OCPPPhase.L2:
- transaction.currentInstanWattsL2 = powerInMeterValueWatts;
+ transaction.currentInstantWattsL2 = powerInMeterValueWatts;
break;
case OCPPPhase.L3:
- transaction.currentInstanWattsL3 = powerInMeterValueWatts;
+ transaction.currentInstantWattsL3 = powerInMeterValueWatts;
break;
default:
transaction.currentInstantWatts = powerInMeterValueWatts;

MODIFY
src/server/ocpp/utils/OCPPUtils.ts
src/server/ocpp/utils/OCPPUtils.ts
@@ -222,10 +222,10 @@ export default class OCPPUtils {
// Set Consumption (currentTotalConsumptionWh, currentTotalInactivitySecs are updated in consumption creation)
transaction.currentConsumptionWh = Utils.convertToFloat(consumption.consumptionWh);
transaction.currentInstantWatts = Utils.convertToFloat(consumption.instantWatts);
- transaction.currentInstanWattsL1 = Utils.convertToFloat(consumption.instantWattsL1);
- transaction.currentInstanWattsL2 = Utils.convertToFloat(consumption.instantWattsL2);
- transaction.currentInstanWattsL3 = Utils.convertToFloat(consumption.instantWattsL3);
- transaction.currentInstanWattsDC = Utils.convertToFloat(consumption.instantWattsDC);
+ transaction.currentInstantWattsL1 = Utils.convertToFloat(consumption.instantWattsL1);
+ transaction.currentInstantWattsL2 = Utils.convertToFloat(consumption.instantWattsL2);
+ transaction.currentInstantWattsL3 = Utils.convertToFloat(consumption.instantWattsL3);
+ transaction.currentInstantWattsDC = Utils.convertToFloat(consumption.instantWattsDC);
transaction.currentInstantVoltage = Utils.convertToFloat(consumption.instantVolts);
transaction.currentInstantVoltageL1 = Utils.convertToFloat(consumption.instantVoltsL1);
transaction.currentInstantVoltageL2 = Utils.convertToFloat(consumption.instantVoltsL2);
@@ -249,13 +249,13 @@ export default class OCPPUtils {
chargingStation, transaction.connectorId, transaction.currentTotalInactivitySecs);
}
- public static async recomputeTransactionConsumptions(tenantID: string, transactionId: number): Promise<number> {
+ public static async rebuildTransactionConsumptions(tenantID: string, transactionId: number): Promise<number> {
let consumptions: Consumption[] = [];
let transactionSimplePricePerKWH;
if (!transactionId) {
throw new BackendError({
source: Constants.CENTRAL_SERVER,
- action: ServerAction.REBUILD_CONSUMPTION,
+ action: ServerAction.REBUILD_TRANSACTION_CONSUMPTIONS,
module: MODULE_NAME, method: 'rebuildConsumptionsFromMeterValues',
message: 'Transaction ID must be provided',
});
@@ -265,7 +265,7 @@ export default class OCPPUtils {
if (!transaction) {
throw new BackendError({
source: Constants.CENTRAL_SERVER,
- action: ServerAction.REBUILD_CONSUMPTION,
+ action: ServerAction.REBUILD_TRANSACTION_CONSUMPTIONS,
module: MODULE_NAME, method: 'rebuildConsumptionsFromMeterValues',
message: `Transaction with ID ${transactionId} does not exist`,
});
@@ -273,7 +273,7 @@ export default class OCPPUtils {
if (!transaction.stop) {
throw new BackendError({
source: Constants.CENTRAL_SERVER,
- action: ServerAction.REBUILD_CONSUMPTION,
+ action: ServerAction.REBUILD_TRANSACTION_CONSUMPTIONS,
module: MODULE_NAME, method: 'rebuildConsumptionsFromMeterValues',
message: `Transaction with ID ${transactionId} is in progress`,
});
@@ -288,7 +288,7 @@ export default class OCPPUtils {
if (!chargingStation) {
throw new BackendError({
source: Constants.CENTRAL_SERVER,
- action: ServerAction.REBUILD_CONSUMPTION,
+ action: ServerAction.REBUILD_TRANSACTION_CONSUMPTIONS,
module: MODULE_NAME, method: 'rebuildConsumptionsFromMeterValues',
message: `Charging Station with ID ${transaction.chargeBoxID} does not exist`,
});
@@ -488,38 +488,38 @@ export default class OCPPUtils {
});
}
// Add Power
- if (transaction.currentInstantWatts > 0 || transaction.currentInstanWattsDC > 0) {
+ if (transaction.currentInstantWatts > 0 || transaction.currentInstantWattsDC > 0) {
stopMeterValues.push({
id: (id++).toString(),
...meterValueBasedProps,
- value: (transaction.currentInstantWatts ? transaction.currentInstantWatts : transaction.currentInstanWattsDC),
+ value: (transaction.currentInstantWatts ? transaction.currentInstantWatts : transaction.currentInstantWattsDC),
attribute: Constants.OCPP_POWER_ACTIVE_IMPORT_ATTRIBUTE
});
}
// Add Power L1
- if (transaction.currentInstanWattsL1 > 0) {
+ if (transaction.currentInstantWattsL1 > 0) {
stopMeterValues.push({
id: (id++).toString(),
...meterValueBasedProps,
- value: transaction.currentInstanWattsL1,
+ value: transaction.currentInstantWattsL1,
attribute: Constants.OCPP_POWER_ACTIVE_IMPORT_L1_ATTRIBUTE
});
}
// Add Power L2
- if (transaction.currentInstanWattsL2 > 0) {
+ if (transaction.currentInstantWattsL2 > 0) {
stopMeterValues.push({
id: (id++).toString(),
...meterValueBasedProps,
- value: transaction.currentInstanWattsL2,
+ value: transaction.currentInstantWattsL2,
attribute: Constants.OCPP_POWER_ACTIVE_IMPORT_L2_ATTRIBUTE
});
}
// Add Power L3
- if (transaction.currentInstanWattsL3 > 0) {
+ if (transaction.currentInstantWattsL3 > 0) {
stopMeterValues.push({
id: (id++).toString(),
...meterValueBasedProps,
- value: transaction.currentInstanWattsL3,
+ value: transaction.currentInstantWattsL3,
attribute: Constants.OCPP_POWER_ACTIVE_IMPORT_L3_ATTRIBUTE
});
}

MODIFY
src/server/rest/CentralRestServerService.ts
src/server/rest/CentralRestServerService.ts
@@ -157,6 +157,7 @@ class RequestMapper {
[ServerAction.TRANSACTIONS_ACTIVE]: TransactionService.handleGetTransactionsActive.bind(this),
[ServerAction.TRANSACTIONS_IN_ERROR]: TransactionService.handleGetTransactionsInError.bind(this),
[ServerAction.TRANSACTION_YEARS]: TransactionService.handleGetTransactionYears.bind(this),
+ [ServerAction.REBUILD_TRANSACTION_CONSUMPTIONS]: TransactionService.handleRebuildTransactionConsumptions.bind(this),
[ServerAction.UNASSIGNED_TRANSACTIONS_COUNT]: TransactionService.handleGetUnassignedTransactionsCount.bind(this),
[ServerAction.CHARGING_STATION_CONSUMPTION_STATISTICS]: StatisticService.handleGetChargingStationConsumptionStatistics.bind(this),
[ServerAction.CHARGING_STATION_USAGE_STATISTICS]: StatisticService.handleGetChargingStationUsageStatistics.bind(this),

MODIFY
src/server/rest/service/TransactionService.ts
src/server/rest/service/TransactionService.ts
@@ -185,6 +185,30 @@ export default class TransactionService {
next();
}
+ public static async handleRebuildTransactionConsumptions(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
+ // Check Auth
+ if (!Authorizations.canUpdateTransaction(req.user)) {
+ throw new AppAuthError({
+ errorCode: HTTPAuthError.ERROR,
+ user: req.user,
+ action: Action.UPDATE, entity: Entity.TRANSACTION,
+ module: MODULE_NAME, method: 'handleRebuildTransactionConsumptions'
+ });
+ }
+ // Filter
+ const filteredRequest = TransactionSecurity.filterTransactionRequest(req.query);
+ UtilsService.assertIdIsProvided(action, filteredRequest.ID.toString(), MODULE_NAME, 'handleRebuildTransactionConsumptions', req.user);
+ // Get Transaction
+ const transaction = await TransactionStorage.getTransaction(req.user.tenantID, filteredRequest.ID);
+ UtilsService.assertObjectExists(action, transaction, `Transaction with ID '${filteredRequest.ID}' does not exist`,
+ MODULE_NAME, 'handleRebuildTransactionConsumptions', req.user);
+ // Get unassigned transactions
+ const nbrOfConsumptions = await OCPPUtils.rebuildTransactionConsumptions(req.user.tenantID, filteredRequest.ID);
+ // Return
+ res.json({ nbrOfConsumptions, ...Constants.REST_RESPONSE_SUCCESS });
+ next();
+ }
+
public static async handleAssignTransactionsToUser(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Check auths
if (!Authorizations.canUpdateTransaction(req.user)) {

MODIFY
src/server/rest/service/security/TransactionSecurity.ts
src/server/rest/service/security/TransactionSecurity.ts
-import { HttpAssignTransactionsToUserRequest, HttpConsumptionFromTransactionRequest, HttpTransactionRequest, HttpTransactionsRefundRequest, HttpTransactionsRequest } from '../../../../types/requests/HttpTransactionRequest';
+import { HttpAssignTransactionsToUserRequest, HttpConsumptionFromTransactionRequest, HttpTransactionRequest, HttpTransactionsRefundRequest, HttpTransactionsRequest, HttpUnassignTransactionsToUserRequest } from '../../../../types/requests/HttpTransactionRequest';
import Transaction, { TransactionConsumption } from '../../../../types/Transaction';
import Authorizations from '../../../../authorization/Authorizations';
@@ -25,7 +25,7 @@ export default class TransactionSecurity {
return { UserID: request.UserID ? sanitize(request.UserID) : null };
}
- static filterUnassignedTransactionsCountRequest(request: any) {
+ static filterUnassignedTransactionsCountRequest(request: any): HttpUnassignTransactionsToUserRequest {
return { UserID: request.UserID ? sanitize(request.UserID) : null };
}
@@ -139,10 +139,10 @@ export default class TransactionSecurity {
}
if (!transaction.stop) {
filteredTransaction.currentInstantWatts = transaction.currentInstantWatts;
- filteredTransaction.currentInstanWattsL1 = transaction.currentInstanWattsL1;
- filteredTransaction.currentInstanWattsL2 = transaction.currentInstanWattsL2;
- filteredTransaction.currentInstanWattsL3 = transaction.currentInstanWattsL3;
- filteredTransaction.currentInstanWattsDC = transaction.currentInstanWattsDC;
+ filteredTransaction.currentInstantWattsL1 = transaction.currentInstantWattsL1;
+ filteredTransaction.currentInstantWattsL2 = transaction.currentInstantWattsL2;
+ filteredTransaction.currentInstantWattsL3 = transaction.currentInstantWattsL3;
+ filteredTransaction.currentInstantWattsDC = transaction.currentInstantWattsDC;
filteredTransaction.currentTotalConsumptionWh = transaction.currentTotalConsumptionWh;
filteredTransaction.currentTotalInactivitySecs = transaction.currentTotalInactivitySecs;
filteredTransaction.currentInactivityStatus = transaction.currentInactivityStatus;

MODIFY
src/storage/mongodb/TransactionStorage.ts
src/storage/mongodb/TransactionStorage.ts
@@ -77,10 +77,10 @@ export default class TransactionStorage {
currentCumulatedPrice: Utils.convertToFloat(transactionToSave.currentCumulatedPrice),
transactionEndReceived: Utils.convertToBoolean(transactionToSave.transactionEndReceived),
currentInstantWatts: Utils.convertToFloat(transactionToSave.currentInstantWatts),
- currentInstanWattsL1: Utils.convertToFloat(transactionToSave.currentInstanWattsL1),
- currentInstanWattsL2: Utils.convertToFloat(transactionToSave.currentInstanWattsL2),
- currentInstanWattsL3: Utils.convertToFloat(transactionToSave.currentInstanWattsL3),
- currentInstanWattsDC: Utils.convertToFloat(transactionToSave.currentInstanWattsDC),
+ currentInstantWattsL1: Utils.convertToFloat(transactionToSave.currentInstantWattsL1),
+ currentInstantWattsL2: Utils.convertToFloat(transactionToSave.currentInstantWattsL2),
+ currentInstantWattsL3: Utils.convertToFloat(transactionToSave.currentInstantWattsL3),
+ currentInstantWattsDC: Utils.convertToFloat(transactionToSave.currentInstantWattsDC),
currentTotalConsumptionWh: Utils.convertToFloat(transactionToSave.currentTotalConsumptionWh),
currentTotalDurationSecs: Utils.convertToInt(transactionToSave.currentTotalDurationSecs),
currentInstantVoltage: Utils.convertToFloat(transactionToSave.currentInstantVoltage),
@@ -117,10 +117,10 @@ export default class TransactionStorage {
};
// Remove runtime props
delete transactionMDB.currentInstantWatts;
- delete transactionMDB.currentInstanWattsL1;
- delete transactionMDB.currentInstanWattsL2;
- delete transactionMDB.currentInstanWattsL3;
- delete transactionMDB.currentInstanWattsDC;
+ delete transactionMDB.currentInstantWattsL1;
+ delete transactionMDB.currentInstantWattsL2;
+ delete transactionMDB.currentInstantWattsL3;
+ delete transactionMDB.currentInstantWattsDC;
delete transactionMDB.currentCumulatedPrice;
delete transactionMDB.currentSignedData;
delete transactionMDB.currentStateOfCharge;

MODIFY
src/types/Server.ts
src/types/Server.ts
@@ -166,7 +166,7 @@ export enum ServerAction {
EXTRA_INACTIVITY = 'ExtraInactivity',
CONSUMPTION = 'Consumption',
- REBUILD_CONSUMPTION = 'RebuildConsumption',
+ REBUILD_TRANSACTION_CONSUMPTIONS = 'RebuildTransactionConsumptions',
WS_ERROR = 'WSError',
WS_CLIENT_ERROR = 'WSClientError',

MODIFY
src/types/Transaction.ts
src/types/Transaction.ts
@@ -64,10 +64,10 @@ export default interface Transaction {
currentTotalDurationSecs?: number;
transactionEndReceived?: boolean;
currentInstantWatts: number;
- currentInstanWattsL1?: number;
- currentInstanWattsL2?: number;
- currentInstanWattsL3?: number;
- currentInstanWattsDC?: number;
+ currentInstantWattsL1?: number;
+ currentInstantWattsL2?: number;
+ currentInstantWattsL3?: number;
+ currentInstantWattsDC?: number;
currentInstantVoltage?: number;
currentInstantVoltageL1?: number;
currentInstantVoltageL2?: number;

MODIFY
src/types/requests/HttpTransactionRequest.ts
src/types/requests/HttpTransactionRequest.ts
@@ -8,7 +8,7 @@ export interface HttpAssignTransactionsToUserRequest {
UserID?: string;
}
-export interface HttpAssignTransactionsToUserRequest {
+export interface HttpUnassignTransactionsToUserRequest {
UserID?: string;
}

Add rebuild of consumptions + fixed typos