cdr export feature
MODIFY
src/server/rest/CentralRestServerService.ts
src/server/rest/CentralRestServerService.ts
@@ -168,6 +168,7 @@ class RequestMapper {
[ServerAction.TRANSACTION_YEARS]: TransactionService.handleGetTransactionYears.bind(this),
[ServerAction.REBUILD_TRANSACTION_CONSUMPTIONS]: TransactionService.handleRebuildTransactionConsumptions.bind(this),
[ServerAction.UNASSIGNED_TRANSACTIONS_COUNT]: TransactionService.handleGetUnassignedTransactionsCount.bind(this),
+ [ServerAction.GET_OCPI_DATA]: TransactionService.handleGetOcpiDataFromTransaction.bind(this),
[ServerAction.CHARGING_STATION_CONSUMPTION_STATISTICS]: StatisticService.handleGetChargingStationConsumptionStatistics.bind(this),
[ServerAction.CHARGING_STATION_USAGE_STATISTICS]: StatisticService.handleGetChargingStationUsageStatistics.bind(this),
[ServerAction.CHARGING_STATION_INACTIVITY_STATISTICS]: StatisticService.handleGetChargingStationInactivityStatistics.bind(this),

MODIFY
src/server/rest/v1/service/TransactionService.ts
src/server/rest/v1/service/TransactionService.ts
@@ -631,6 +631,26 @@ export default class TransactionService {
TransactionService.getTransactions.bind(this), TransactionService.convertToCSV.bind(this));
}
+ public static async handleGetOcpiDataFromTransaction(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
+ // Check auth
+ if (!Authorizations.canListTransactions(req.user)) {
+ throw new AppAuthError({
+ errorCode: HTTPAuthError.ERROR,
+ user: req.user,
+ action: Action.LIST,
+ entity: Entity.TRANSACTIONS,
+ module: MODULE_NAME,
+ method: 'handleGetOcpiDataFromTransaction'
+ });
+ }
+ // Filter
+ const filteredRequest = TransactionSecurity.filterTransactionRequest(req.query);
+ UtilsService.assertIdIsProvided(action, filteredRequest.ID, MODULE_NAME, 'handleGetOcpiDataFromTransaction', req.user);
+ // Get Ocpi Data
+ res.json(await TransactionStorage.getOcpiDataFromTransaction(req.user.tenantID, filteredRequest.ID));
+ next();
+ }
+
public static async handleGetTransactionsInError(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Check auth
if (!Authorizations.canListTransactionsInError(req.user)) {

MODIFY
src/storage/mongodb/TransactionStorage.ts
src/storage/mongodb/TransactionStorage.ts
import RefundReport, { RefundStatus } from '../../types/Refund';
+import Transaction, { OcpiData } from '../../types/Transaction';
import { TransactionInError, TransactionInErrorType } from '../../types/InError';
import global, { FilterParams } from './../../types/GlobalType';
@@ -10,7 +11,6 @@ import DbParams from '../../types/database/DbParams';
import Logging from '../../utils/Logging';
import { NotifySessionNotStarted } from '../../types/Notification';
import { ServerAction } from '../../types/Server';
-import Transaction from '../../types/Transaction';
import User from '../../types/User';
import Utils from '../../utils/Utils';
import moment from 'moment';
@@ -1040,6 +1040,25 @@ export default class TransactionStorage {
Logging.traceEnd(MODULE_NAME, '_findAvailableID', uniqueTimerID);
}
+ public static async getOcpiDataFromTransaction(tenantID: string, transactionID: number = Constants.UNKNOWN_NUMBER_ID): Promise<OcpiData> {
+ // Debug
+ const uniqueTimerID = Logging.traceStart(MODULE_NAME, 'getTransaction');
+ // Check
+ await Utils.checkTenant(tenantID);
+ // Get OcpiData
+ const ocpiDataMDB = await global.database.getCollection<any>(tenantID, 'transactions')
+ .aggregate([
+ { $match: { _id: transactionID } },
+ { $project: { _id: 0, ocpiData: 1 } }
+ ]).toArray();
+ // Debug
+ Logging.traceEnd(MODULE_NAME, 'getTransaction', uniqueTimerID, { transactionID });
+ if (ocpiDataMDB && ocpiDataMDB.length > 0 && ocpiDataMDB[0].ocpiData) {
+ return ocpiDataMDB[0].ocpiData;
+ }
+ return {};
+ }
+
public static async getNotStartedTransactions(tenantID: string,
params: { checkPastAuthorizeMins: number; sessionShouldBeStartedAfterMins: number }): Promise<DataResult<NotifySessionNotStarted>> {
// Debug

MODIFY
src/types/Server.ts
src/types/Server.ts
@@ -239,6 +239,8 @@ export enum ServerAction {
TRANSACTION = 'Transaction',
TRANSACTION_CONSUMPTION = 'TransactionConsumption',
+ GET_OCPI_DATA = 'GetOcpiData',
+
CHARGING_STATION_CONSUMPTION_STATISTICS = 'ChargingStationConsumptionStatistics',
CHARGING_STATION_USAGE_STATISTICS = 'ChargingStationUsageStatistics',
CHARGING_STATION_INACTIVITY_STATISTICS = 'ChargingStationInactivityStatistics',

MODIFY
src/types/Transaction.ts
src/types/Transaction.ts
@@ -70,12 +70,14 @@ export default interface Transaction extends AbstractCurrentConsumption {
uniqueId?: string;
values?: TransactionConsumption[];
billingData?: BillingTransactionData;
- ocpiData?: {
+ ocpiData?: OcpiData;
+}
+
+export interface OcpiData {
session?: OCPISession;
cdr?: OCPICdr;
sessionCheckedOn?: Date;
cdrCheckedOn?: Date;
- };
}
export interface CSPhasesUsed {

cdr export feature