Fixed cannot export OCPI CDR endpoint
MODIFY
src/assets/server/rest/v1/docs/e-mobility-oas.json
src/assets/server/rest/v1/docs/e-mobility-oas.json
}
}
},
- "/api/transactions/{id}/ocpi/cdrs": {
+ "/api/transactions/{id}/ocpi/cdr": {
"post": {
"security": [
{
}
}
},
- "/api/transactions/{id}/ocpi/cdrs/export": {
+ "/api/transactions/{id}/ocpi/cdr/export": {
"get": {
"security": [
{
],
"parameters": [
{
- "$ref": "#/components/parameters/WithUser"
- },
- {
- "$ref": "#/components/parameters/WithCar"
- },
- {
- "$ref": "#/components/parameters/WithTag"
+ "$ref": "#/components/parameters/transactionID"
}
],
"description": "Export Transaction CDR",

ADD
src/assets/server/rest/v1/schemas/transaction/transaction-cdr-export.json
+{
+ "$id": "transaction-cdr-export",
+ "title": "Get Transaction Request",
+ "type": "object",
+ "properties": {
+ "ID": {
+ "$ref": "transaction#/definitions/id"
+ }
+ },
+ "required": [
+ "ID"
+ ]
+}

MODIFY
src/server/rest/v1/service/TransactionService.ts
src/server/rest/v1/service/TransactionService.ts
@@ -722,7 +722,7 @@ export default class TransactionService {
public static async getRefundedTransactionsToExport(req: Request): Promise<DataResult<Transaction>> {
req.query.Status = 'completed';
- return await TransactionService.getTransactions(req, ServerAction.TRANSACTIONS_TO_REFUND_EXPORT, {}, [
+ return TransactionService.getTransactions(req, ServerAction.TRANSACTIONS_TO_REFUND_EXPORT, {}, [
'id', 'chargeBoxID', 'timestamp', 'issuer', 'stateOfCharge', 'timezone', 'connectorId', 'meterStart', 'siteAreaID', 'siteID', 'companyID',
'refundData.reportId', 'refundData.refundedAt', 'refundData.status', 'site.name', 'siteArea.name', 'company.name',
'stop.roundedPrice', 'stop.price', 'stop.priceUnit', 'stop.inactivityStatus', 'stop.stateOfCharge', 'stop.timestamp', 'stop.totalConsumptionWh',
@@ -744,7 +744,7 @@ export default class TransactionService {
});
}
// Filter
- const filteredRequest = TransactionValidator.getInstance().validateTransactionGetReq(req.query);
+ const filteredRequest = TransactionValidator.getInstance().validateTransactionCdrExportReq(req.query);
UtilsService.assertIdIsProvided(action, filteredRequest.ID, MODULE_NAME, 'handleExportTransactionOcpiCdr', req.user);
// Get Transaction
const transaction = await TransactionStorage.getTransaction(req.tenant, filteredRequest.ID, {}, ['id', 'ocpiData']);

MODIFY
src/server/rest/v1/validator/TransactionValidator.ts
src/server/rest/v1/validator/TransactionValidator.ts
-import { HttpAssignTransactionsToUserRequest, HttpConsumptionFromTransactionRequest, HttpPushTransactionCdrRequest, HttpTransactionRequest, HttpTransactionsRequest, HttpUnassignTransactionsToUserRequest } from '../../../../types/requests/HttpTransactionRequest';
+import { HttpAssignTransactionsToUserRequest, HttpConsumptionFromTransactionRequest, HttpExportTransactionCdrRequest, HttpPushTransactionCdrRequest, HttpTransactionRequest, HttpTransactionsRequest, HttpUnassignTransactionsToUserRequest } from '../../../../types/requests/HttpTransactionRequest';
import Schema from '../../../../types/validator/Schema';
import SchemaValidator from '../../../../validator/SchemaValidator';
@@ -11,6 +11,7 @@ export default class TransactionValidator extends SchemaValidator {
private transactionGet: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/transaction/transaction-get.json`, 'utf8'));
private transactionsByIDsGet: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/transaction/transactions-by-ids-get.json`, 'utf8'));
private transactionCdrPush: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/transaction/transaction-cdr-push.json`, 'utf8'));
+ private transactionCdrExport: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/transaction/transaction-cdr-export.json`, 'utf8'));
private transactionConsumptionsGet: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/transaction/transaction-consumptions-get.json`, 'utf8'));
private transactionsUserAssign: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/transaction/transactions-user-assign.json`, 'utf8'));
private transactionsUnassignedCountGet: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/transaction/transactions-unassigned-count-get.json`, 'utf8'));
@@ -36,6 +37,10 @@ export default class TransactionValidator extends SchemaValidator {
return this.validate(this.transactionGet, data);
}
+ public validateTransactionCdrExportReq(data: Record<string, unknown>): HttpExportTransactionCdrRequest {
+ return this.validate(this.transactionCdrExport, data);
+ }
+
public validateTransactionsByIDsGetReq(data: Record<string, unknown>): { transactionsIDs: number[] } {
return this.validate(this.transactionsByIDsGet, data);
}

MODIFY
src/types/requests/HttpTransactionRequest.ts
src/types/requests/HttpTransactionRequest.ts
@@ -25,6 +25,10 @@ export interface HttpPushTransactionCdrRequest {
transactionId: number;
}
+export interface HttpExportTransactionCdrRequest {
+ ID: number;
+}
+
export interface HttpTransactionsRequest extends HttpDatabaseRequest {
ChargingStationID: string;
Issuer: boolean;

Fixed cannot export OCPI CDR endpoint