Added getTransaction validation schema
ADD
src/assets/server/rest/v1/schemas/transaction/transaction-get.json
+{
+ "title": "Get Transaction Request",
+ "type": "object",
+ "properties": {
+ "ID": {
+ "$ref": "transaction.json#/definitions/id"
+ },
+ "WithTag": {
+ "type": "boolean",
+ "sanitize": "mongo"
+ },
+ "WithUser": {
+ "type": "boolean",
+ "sanitize": "mongo"
+ },
+ "WithCar": {
+ "type": "boolean",
+ "sanitize": "mongo"
+ }
+ }
+}

MODIFY
src/server/rest/v1/service/TransactionService.ts
src/server/rest/v1/service/TransactionService.ts
@@ -337,7 +337,7 @@ export default class TransactionService {
});
}
// Filter
- const filteredRequest = TransactionSecurity.filterTransactionRequest(req.query);
+ const filteredRequest = TransactionValidator.getInstance().validateTransactionGetReq(req.query);
UtilsService.assertIdIsProvided(action, filteredRequest.ID.toString(), MODULE_NAME, 'handleRebuildTransactionConsumptions', req.user);
// Get Transaction
const transaction = await TransactionStorage.getTransaction(
@@ -638,7 +638,7 @@ export default class TransactionService {
public static async handleGetTransaction(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const filteredRequest = TransactionSecurity.filterTransactionRequest(req.query);
+ const filteredRequest = TransactionValidator.getInstance().validateTransactionGetReq(req.query);
UtilsService.assertIdIsProvided(action, filteredRequest.ID, MODULE_NAME, 'handleGetTransaction', req.user);
// Get Transaction
const transaction = await TransactionStorage.getTransaction(req.user.tenantID, filteredRequest.ID,
@@ -851,7 +851,7 @@ export default class TransactionService {
});
}
// Filter
- const filteredRequest = TransactionSecurity.filterTransactionRequest(req.query);
+ const filteredRequest = TransactionValidator.getInstance().validateTransactionGetReq(req.query);
UtilsService.assertIdIsProvided(action, filteredRequest.ID, MODULE_NAME, 'handleExportTransactionOcpiCdr', req.user);
// Get Transaction
const transaction = await TransactionStorage.getTransaction(req.user.tenantID, filteredRequest.ID, {}, ['id', 'ocpiData']);

MODIFY
src/server/rest/v1/validator/TransactionValidator.ts
src/server/rest/v1/validator/TransactionValidator.ts
-import { HttpTransactionsRequest } from '../../../../types/requests/HttpTransactionRequest';
+import { HttpTransactionRequest, HttpTransactionsRequest } from '../../../../types/requests/HttpTransactionRequest';
+
import Schema from '../../../../types/validator/Schema';
import SchemaValidator from './SchemaValidator';
import fs from 'fs';
@@ -7,11 +8,13 @@ import global from '../../../../types/GlobalType';
export default class TransactionValidator extends SchemaValidator {
private static instance: TransactionValidator | undefined;
private transactionsGet: Schema;
+ private transactionGet: Schema;
private constructor() {
super('TransactionValidator');
this.transactionsGet = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/transaction/transactions-get.json`, 'utf8'));
+ this.transactionGet = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/transaction/transaction-get.json`, 'utf8'));
}
public static getInstance(): TransactionValidator {
@@ -26,4 +29,10 @@ export default class TransactionValidator extends SchemaValidator {
this.validate(this.transactionsGet, data);
return data;
}
+
+ public validateTransactionGetReq(data: any): HttpTransactionRequest {
+ // Validate schema
+ this.validate(this.transactionGet, data);
+ return data;
+ }
}

Added getTransaction validation schema