Added pushTransactionCDR validation schema
ADD
src/assets/server/rest/v1/schemas/transaction/transaction-push-cdr.json
+{
+ "title": "Push Transaction CDR Request",
+ "type": "object",
+ "properties": {
+ "transactionId": {
+ "$ref": "transaction.json#/definitions/id"
+ }
+ },
+ "required": [
+ "transactionId"
+ ]
+}

MODIFY
src/assets/server/rest/v1/schemas/transaction/transactions-get-by-ids.json
src/assets/server/rest/v1/schemas/transaction/transactions-get-by-ids.json
"title": "Get Transactions by IDs Request",
"type": "object",
"properties": {
- "transactionIDs": {
+ "transactionsIDs": {
"type": "array",
"items": {
"$ref": "transaction.json#/definitions/id"
}
+ }
},
"required": [
- "transactionIDs"
+ "transactionsIDs"
]
}
-}

MODIFY
src/server/rest/v1/service/TransactionService.ts
src/server/rest/v1/service/TransactionService.ts
@@ -178,7 +178,7 @@ export default class TransactionService {
public static async handlePushTransactionCdr(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const filteredRequest = TransactionSecurity.filterPushTransactionCdrRequest(req.body);
+ const filteredRequest = TransactionValidator.getInstance().validateTransactionPushCDRReq(req.body);
// Check Mandatory fields
UtilsService.assertIdIsProvided(action, filteredRequest.transactionId, MODULE_NAME, 'handlePushTransactionCdr', req.user);
// Check auth
@@ -416,7 +416,7 @@ export default class TransactionService {
public static async handleDeleteTransaction(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const transactionId = TransactionSecurity.filterTransactionRequestByID(req.query);
+ const transactionId = TransactionValidator.getInstance().validateTransactionGetReq(req.query).ID;
// Check auth
if (!await Authorizations.canDeleteTransaction(req.user)) {
throw new AppAuthError({
@@ -439,7 +439,12 @@ export default class TransactionService {
public static async handleDeleteTransactions(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const transactionsIds = TransactionValidator.getInstance().validateTransactionsGetByIDsReq(req.body);
+ try {
+ TransactionValidator.getInstance().validateTransactionsGetByIDsReq(req.body);
+ } catch (e) {
+ const a = 5;
+ }
+ const transactionsIds = TransactionValidator.getInstance().validateTransactionsGetByIDsReq(req.body).transactionsIDs;
// Check auth
if (!await Authorizations.canDeleteTransaction(req.user)) {
throw new AppAuthError({

MODIFY
src/server/rest/v1/validator/TransactionValidator.ts
src/server/rest/v1/validator/TransactionValidator.ts
-import { HttpTransactionRequest, HttpTransactionsRequest } from '../../../../types/requests/HttpTransactionRequest';
+import { HttpPushTransactionCdrRequest, HttpTransactionRequest, HttpTransactionsRequest } from '../../../../types/requests/HttpTransactionRequest';
import Schema from '../../../../types/validator/Schema';
import SchemaValidator from './SchemaValidator';
@@ -10,6 +10,7 @@ export default class TransactionValidator extends SchemaValidator {
private transactionsGet: Schema;
private transactionGet: Schema;
private transactionsGetByIDs: Schema;
+ private transactionPushCDR: Schema;
private constructor() {
@@ -17,6 +18,7 @@ export default class TransactionValidator extends SchemaValidator {
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'));
this.transactionsGetByIDs = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/transaction/transactions-get-by-ids.json`, 'utf8'));
+ this.transactionPushCDR = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/transaction/transaction-push-cdr.json`, 'utf8'));
}
public static getInstance(): TransactionValidator {
@@ -38,9 +40,15 @@ export default class TransactionValidator extends SchemaValidator {
return data;
}
- public validateTransactionsGetByIDsReq(data: any): number[] {
+ public validateTransactionsGetByIDsReq(data: any): { transactionsIDs: number[] } {
// Validate schema
this.validate(this.transactionsGetByIDs, data);
return data;
}
+
+ public validateTransactionPushCDRReq(data: any): HttpPushTransactionCdrRequest {
+ // Validate schema
+ this.validate(this.transactionPushCDR, data);
+ return data;
+ }
}

Added pushTransactionCDR validation schema