Additional changes to transaction storage
MODIFY
src/client/ocpi/CpoOCPIClient.ts
src/client/ocpi/CpoOCPIClient.ts
@@ -488,7 +488,7 @@ export default class CpoOCPIClient extends OCPIClient {
};
// Perfs trace
const startTime = new Date().getTime();
- const transactions = await TransactionStorage.getTransactions(this.tenant.id, {
+ const transactions = await TransactionStorage.getTransactions(this.tenant, {
issuer: true,
ocpiSessionChecked: false
}, Constants.DB_PARAMS_MAX_LIMIT);

MODIFY
src/client/ocpi/EmspOCPIClient.ts
src/client/ocpi/EmspOCPIClient.ts
@@ -508,7 +508,7 @@ export default class EmspOCPIClient extends OCPIClient {
const commandUrl = this.getEndpointUrl('commands', ServerAction.OCPI_START_SESSION) + '/' + OCPICommandType.STOP_SESSION;
const callbackUrl = this.getLocalEndpointUrl('commands') + '/' + OCPICommandType.STOP_SESSION;
// Get transaction
- const transaction = await TransactionStorage.getTransaction(this.tenant.id, transactionId);
+ const transaction = await TransactionStorage.getTransaction(this.tenant, transactionId);
if (!transaction) {
throw new BackendError({
action: ServerAction.OCPI_START_SESSION,

MODIFY
src/integration/asset/lacroix/LacroixAssetIntegration.ts
src/integration/asset/lacroix/LacroixAssetIntegration.ts
@@ -127,7 +127,7 @@ export default class LacroixAssetIntegration extends AssetIntegration<AssetSetti
}
// Get transactions to calculate asset consumption of the current minute
if (moment().diff(moment(consumptions[consumptions.length - 1].lastConsumption.timestamp), 'minutes') <= 1) {
- const transactionResponse = await TransactionStorage.getTransactions(this.tenant.id, { siteAreaIDs:[asset.siteAreaID],
+ const transactionResponse = await TransactionStorage.getTransactions(this.tenant, { siteAreaIDs:[asset.siteAreaID],
stop: { $exists: false } }, Constants.DB_PARAMS_MAX_LIMIT, ['currentInstantWatts', 'currentInstantWattsL1','currentInstantWattsL2','currentInstantWattsL3']);
for (const transaction of transactionResponse.result) {
consumptions[consumptions.length - 1].currentInstantWatts -= transaction.currentInstantWatts;

MODIFY
src/integration/billing/BillingIntegration.ts
src/integration/billing/BillingIntegration.ts
@@ -450,7 +450,7 @@ export default abstract class BillingIntegration {
await Promise.all(billingInvoice.sessions.map(async (session) => {
const transactionID = session.transactionID;
try {
- const transaction = await TransactionStorage.getTransaction(this.tenant.id, Number(transactionID));
+ const transaction = await TransactionStorage.getTransaction(this.tenant, Number(transactionID));
// Update Billing Data
const stop: BillingDataTransactionStop = {
status: BillingStatus.UNBILLED,
@@ -464,7 +464,7 @@ export default abstract class BillingIntegration {
stop
};
// Save to clear billing data
- await TransactionStorage.saveTransactionBillingData(this.tenant.id, transaction.id, transaction.billingData);
+ await TransactionStorage.saveTransactionBillingData(this.tenant, transaction.id, transaction.billingData);
} catch (error) {
await Logging.logError({
tenantID: this.tenant.id,

MODIFY
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/OCPIUtilsService.ts
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/OCPIUtilsService.ts
@@ -481,7 +481,7 @@ export default class OCPIUtilsService {
if (!session.kwh) {
session.kwh = 0;
}
- let transaction: Transaction = await TransactionStorage.getOCPITransactionBySessionID(tenant.id, session.id);
+ let transaction: Transaction = await TransactionStorage.getOCPITransactionBySessionID(tenant, session.id);
if (!transaction) {
const user = await UserStorage.getUser(tenant.id, session.auth_id);
if (!user) {
@@ -590,7 +590,7 @@ export default class OCPIUtilsService {
userID: transaction.userID
};
}
- await TransactionStorage.saveTransaction(tenant.id, transaction);
+ await TransactionStorage.saveTransaction(tenant, transaction);
await this.updateConnector(tenant, transaction);
}
@@ -605,7 +605,7 @@ export default class OCPIUtilsService {
ocpiError: OCPIStatusCode.CODE_2001_INVALID_PARAMETER_ERROR
});
}
- const transaction: Transaction = await TransactionStorage.getOCPITransactionBySessionID(tenant.id, cdr.id);
+ const transaction: Transaction = await TransactionStorage.getOCPITransactionBySessionID(tenant, cdr.id);
if (!transaction) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
@@ -653,7 +653,7 @@ export default class OCPIUtilsService {
transaction.ocpiData = {};
}
transaction.ocpiData.cdr = cdr;
- await TransactionStorage.saveTransaction(tenant.id, transaction);
+ await TransactionStorage.saveTransaction(tenant, transaction);
await this.updateConnector(tenant, transaction);
}

MODIFY
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/cpo/CPOCommandsEndpoint.ts
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/cpo/CPOCommandsEndpoint.ts
@@ -208,7 +208,7 @@ export default class CPOCommandsEndpoint extends AbstractEndpoint {
ocpiError: OCPIStatusCode.CODE_2001_INVALID_PARAMETER_ERROR
});
}
- const transaction = await TransactionStorage.getOCPITransactionBySessionID(tenant.id, stopSession.session_id);
+ const transaction = await TransactionStorage.getOCPITransactionBySessionID(tenant, stopSession.session_id);
if (!transaction) {
await Logging.logError({
tenantID: tenant.id,

MODIFY
src/server/ocpp/services/OCPPService.ts
src/server/ocpp/services/OCPPService.ts
@@ -269,7 +269,7 @@ export default class OCPPService {
// Roaming
await OCPPUtils.processTransactionRoaming(tenant, transaction, chargingStation, transaction.tag, TransactionAction.UPDATE);
// Save Transaction
- await TransactionStorage.saveTransaction(tenant.id, transaction);
+ await TransactionStorage.saveTransaction(tenant, transaction);
// Update Charging Station
await this.updateChargingStationWithTransaction(tenant, chargingStation, transaction);
// Handle End Of charge
@@ -446,7 +446,7 @@ export default class OCPPService {
// Roaming
await OCPPUtils.processTransactionRoaming(tenant, newTransaction, chargingStation, tag, TransactionAction.START);
// Save it
- await TransactionStorage.saveTransaction(tenant.id, newTransaction);
+ await TransactionStorage.saveTransaction(tenant, newTransaction);
// Clean up
await this.updateChargingStationConnectorWithTransaction(tenant, newTransaction, chargingStation, user);
// Save
@@ -565,7 +565,7 @@ export default class OCPPService {
// Roaming
await OCPPUtils.processTransactionRoaming(tenant, transaction, chargingStation, transaction.tag, TransactionAction.STOP);
// Save the transaction
- await TransactionStorage.saveTransaction(tenant.id, transaction);
+ await TransactionStorage.saveTransaction(tenant, transaction);
// Notify User
this.notifyStopTransaction(tenant, chargingStation, transaction, user, alternateUser);
// Recompute the Smart Charging Plan
@@ -834,7 +834,7 @@ export default class OCPPService {
if (statusNotification.status === ChargePointStatus.AVAILABLE) {
// Get the last transaction
const lastTransaction = await TransactionStorage.getLastTransactionFromChargingStation(
- tenant.id, chargingStation.id, connector.connectorId, { withChargingStation: true, withUser: true, withTag: true });
+ tenant, chargingStation.id, connector.connectorId, { withChargingStation: true, withUser: true, withTag: true });
// Transaction completed
if (lastTransaction?.stop) {
// Check Inactivity
@@ -902,7 +902,7 @@ export default class OCPPService {
await this.checkAndSendOICPTransactionCdr(tenant, lastTransaction, chargingStation, lastTransaction.tag);
}
// Save
- await TransactionStorage.saveTransaction(tenant.id, lastTransaction);
+ await TransactionStorage.saveTransaction(tenant, lastTransaction);
} else if (!Utils.isNullOrUndefined(lastTransaction)) {
await Logging.logWarning({
tenantID: tenant.id,
@@ -1426,7 +1426,7 @@ export default class OCPPService {
let activeTransaction: Transaction, lastCheckedTransactionID: number;
do {
// Check if the charging station has already a transaction
- activeTransaction = await TransactionStorage.getActiveTransaction(tenant.id, chargingStation.id, connectorId);
+ activeTransaction = await TransactionStorage.getActiveTransaction(tenant, chargingStation.id, connectorId);
// Exists already?
if (activeTransaction) {
// Avoid infinite Loop
@@ -1445,7 +1445,7 @@ export default class OCPPService {
message: `${Utils.buildConnectorInfo(activeTransaction.connectorId, activeTransaction.id)} Transaction with no consumption has been deleted`
});
// Delete
- await TransactionStorage.deleteTransaction(tenant.id, activeTransaction.id);
+ await TransactionStorage.deleteTransaction(tenant, activeTransaction.id);
// Clear connector
OCPPUtils.clearChargingStationConnector(chargingStation, activeTransaction.connectorId);
} else {
@@ -1685,7 +1685,7 @@ export default class OCPPService {
private async createTransaction(tenant: Tenant, startTransaction: OCPPStartTransactionRequestExtended): Promise<Transaction> {
return {
- id: await TransactionStorage.findAvailableID(tenant.id),
+ id: await TransactionStorage.findAvailableID(tenant),
issuer: true,
chargeBoxID: startTransaction.chargeBoxID,
tagID: startTransaction.idTag,
@@ -1985,7 +1985,7 @@ export default class OCPPService {
detailedMessages: { headers, meterValues }
});
}
- const transaction = await TransactionStorage.getTransaction(tenant.id, meterValues.transactionId, { withUser: true, withTag: true });
+ const transaction = await TransactionStorage.getTransaction(tenant, meterValues.transactionId, { withUser: true, withTag: true });
if (!transaction) {
// Try a Remote Stop the Transaction
if (meterValues.transactionId) {
@@ -2051,7 +2051,7 @@ export default class OCPPService {
private async getTransactionFromStopTransaction(tenant: Tenant, chargingStation: ChargingStation,
headers: OCPPHeader, stopTransaction: OCPPStopTransactionRequestExtended): Promise<Transaction> {
- const transaction = await TransactionStorage.getTransaction(tenant.id, stopTransaction.transactionId, { withUser: true, withTag: true });
+ const transaction = await TransactionStorage.getTransaction(tenant, stopTransaction.transactionId, { withUser: true, withTag: true });
if (!transaction) {
throw new BackendError({
source: chargingStation.id,

MODIFY
src/server/oicp/OICPUtils.ts
src/server/oicp/OICPUtils.ts
@@ -213,7 +213,7 @@ export default class OICPUtils {
// Get the first non used Authorization OICP ID / Session ID
for (const authorization of authorizations.result) {
if (authorization.authorizationId) {
- const oicpTransaction = await TransactionStorage.getOICPTransactionBySessionID(tenant.id, authorization.authorizationId);
+ const oicpTransaction = await TransactionStorage.getOICPTransactionBySessionID(tenant, authorization.authorizationId);
// OICP SessionID not used yet
if (!oicpTransaction) {
sessionId = authorization.authorizationId;

MODIFY
src/server/oicp/oicp-services-impl/oicp-2.3.0/CPORemoteAuthorizationsEndpoint.ts
src/server/oicp/oicp-services-impl/oicp-2.3.0/CPORemoteAuthorizationsEndpoint.ts
@@ -152,7 +152,7 @@ export default class CPORemoteAuthorizationsEndpoint extends AbstractEndpoint {
const session = {} as Partial<OICPSession>;
session.id = authorizeRemoteStop.SessionID;
session.providerID = authorizeRemoteStop.ProviderID;
- const transaction = await TransactionStorage.getOICPTransactionBySessionID(tenant.id, authorizeRemoteStop.SessionID);
+ const transaction = await TransactionStorage.getOICPTransactionBySessionID(tenant, authorizeRemoteStop.SessionID);
if (!transaction) {
await Logging.logError({
tenantID: tenant.id,

Additional changes to transaction storage