Updated endpoint + Get transaction + Check if OCPI exists
MODIFY
src/server/rest/CentralRestServerService.ts
src/server/rest/CentralRestServerService.ts
@@ -167,7 +167,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.TRANSACTION_OCPI_CDR_EXPORT]: TransactionService.handleExportTransactionOcpiCdr.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
@@ -726,7 +726,7 @@ export default class TransactionService {
]);
}
- public static async handleGetOcpiDataFromTransaction(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
+ public static async handleExportTransactionOcpiCdr(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Check auth
if (!Authorizations.canListTransactions(req.user)) {
throw new AppAuthError({
@@ -735,14 +735,29 @@ export default class TransactionService {
action: Action.LIST,
entity: Entity.TRANSACTIONS,
module: MODULE_NAME,
- method: 'handleGetOcpiDataFromTransaction'
+ method: 'handleExportTransactionOcpiCdr'
});
}
// Filter
const filteredRequest = TransactionSecurity.filterTransactionRequest(req.query);
- UtilsService.assertIdIsProvided(action, filteredRequest.ID, MODULE_NAME, 'handleGetOcpiDataFromTransaction', req.user);
+ UtilsService.assertIdIsProvided(action, filteredRequest.ID, MODULE_NAME, 'handleExportTransactionOcpiCdr', req.user);
+ // Get Transaction
+ const transaction = await TransactionStorage.getTransaction(req.user.tenantID, filteredRequest.ID, ['id', 'ocpiData']);
+ UtilsService.assertObjectExists(action, transaction, `Transaction with ID '${filteredRequest.ID}' does not exist`,
+ MODULE_NAME, 'handleExportTransactionOcpiCdr', req.user);
+ // Check
+ if (!transaction?.ocpiData) {
+ throw new AppError({
+ source: Constants.CENTRAL_SERVER,
+ errorCode: HTTPError.GENERAL_ERROR,
+ message: `Transaction ID '${transaction.id}' does not contain roaming data`,
+ module: MODULE_NAME, method: 'handleExportTransactionOcpiCdr',
+ user: req.user,
+ action: action
+ });
+ }
// Get Ocpi Data
- res.json(await TransactionStorage.getOcpiDataFromTransaction(req.user.tenantID, filteredRequest.ID));
+ res.json(transaction.ocpiData.cdr);
next();
}

MODIFY
src/storage/mongodb/TransactionStorage.ts
src/storage/mongodb/TransactionStorage.ts
@@ -1031,25 +1031,6 @@ export default class TransactionStorage {
Logging.traceEnd(tenantID, MODULE_NAME, '_findAvailableID', uniqueTimerID);
}
- public static async getOcpiDataFromTransaction(tenantID: string, transactionID: number = Constants.UNKNOWN_NUMBER_ID): Promise<OcpiData> {
- // Debug
- const uniqueTimerID = Logging.traceStart(tenantID, MODULE_NAME, 'getTransaction');
- // Check
- await DatabaseUtils.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(tenantID, 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
@@ -247,7 +247,7 @@ export enum ServerAction {
TRANSACTION = 'Transaction',
TRANSACTION_CONSUMPTION = 'TransactionConsumption',
- GET_OCPI_DATA = 'GetOcpiData',
+ TRANSACTION_OCPI_CDR_EXPORT = 'TransactionOcpiCdrExport',
CHARGING_STATION_CONSUMPTION_STATISTICS = 'ChargingStationConsumptionStatistics',
CHARGING_STATION_USAGE_STATISTICS = 'ChargingStationUsageStatistics',

Updated endpoint + Get transaction + Check if OCPI exists