Added getTransactionsByIDs validation schema
MODIFY
src/assets/server/rest/v1/schemas/transaction/transaction-get.json
src/assets/server/rest/v1/schemas/transaction/transaction-get.json
"type": "boolean",
"sanitize": "mongo"
}
- }
+ },
+ "required": [
+ "ID"
+ ]
}

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

MODIFY
src/server/rest/v1/service/TransactionService.ts
src/server/rest/v1/service/TransactionService.ts
@@ -439,7 +439,7 @@ export default class TransactionService {
public static async handleDeleteTransactions(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const transactionsIds = TransactionSecurity.filterTransactionRequestByIDs(req.body);
+ const transactionsIds = TransactionValidator.getInstance().validateTransactionsGetByIDsReq(req.body);
// 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
@@ -9,12 +9,14 @@ export default class TransactionValidator extends SchemaValidator {
private static instance: TransactionValidator | undefined;
private transactionsGet: Schema;
private transactionGet: Schema;
+ private transactionsGetByIDs: 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'));
+ this.transactionsGetByIDs = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/transaction/transactions-get-by-ids.json`, 'utf8'));
}
public static getInstance(): TransactionValidator {
@@ -35,4 +37,10 @@ export default class TransactionValidator extends SchemaValidator {
this.validate(this.transactionGet, data);
return data;
}
+
+ public validateTransactionsGetByIDsReq(data: any): number[] {
+ // Validate schema
+ this.validate(this.transactionsGetByIDs, data);
+ return data;
+ }
}

Added getTransactionsByIDs validation schema