Added unassigned-transactions-count validation schema
ADD
src/assets/server/rest/v1/schemas/transaction/transactions-unassigned-count-get.json
+{
+ "title": "Get unassigned Transaction count Request",
+ "type": "object",
+ "properties": {
+ "TagID": {
+ "$ref": "tag.json#/definitions/id"
+ }
+ },
+ "required": [
+ "TagID"
+ ]
+}

MODIFY
src/server/rest/v1/service/TransactionService.ts
src/server/rest/v1/service/TransactionService.ts
@@ -305,16 +305,7 @@ export default class TransactionService {
});
}
// Filter
- const filteredRequest = TransactionSecurity.filterUnassignedTransactionsCountRequest(req.query);
- if (!filteredRequest.TagID) {
- throw new AppError({
- source: Constants.CENTRAL_SERVER,
- errorCode: HTTPError.GENERAL_ERROR,
- message: 'Tag ID must be provided',
- module: MODULE_NAME, method: 'handleGetUnassignedTransactionsCount',
- user: req.user, action: action
- });
- }
+ const filteredRequest = TransactionValidator.getInstance().validateTransactionsUnassignedCountReq(req.query);
// Get the user
const tag = await TagStorage.getTag(req.tenant, filteredRequest.TagID);
UtilsService.assertObjectExists(action, tag, `Tag ID '${filteredRequest.TagID}' does not exist`,

MODIFY
src/server/rest/v1/validator/TransactionValidator.ts
src/server/rest/v1/validator/TransactionValidator.ts
-import { HttpAssignTransactionsToUserRequest, HttpConsumptionFromTransactionRequest, HttpPushTransactionCdrRequest, HttpTransactionRequest, HttpTransactionsRequest } from '../../../../types/requests/HttpTransactionRequest';
+import { HttpAssignTransactionsToUserRequest, HttpConsumptionFromTransactionRequest, HttpPushTransactionCdrRequest, HttpTransactionRequest, HttpTransactionsRequest, HttpUnassignTransactionsToUserRequest } from '../../../../types/requests/HttpTransactionRequest';
import Schema from '../../../../types/validator/Schema';
import SchemaValidator from './SchemaValidator';
@@ -13,6 +13,7 @@ export default class TransactionValidator extends SchemaValidator {
private transactionPushCDR: Schema;
private transactionGetConsumption: Schema;
private transactionsAssignUser: Schema;
+ private transactionsUnassignedCountGet: Schema;
private constructor() {
@@ -23,6 +24,7 @@ export default class TransactionValidator extends SchemaValidator {
this.transactionPushCDR = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/transaction/transaction-push-cdr.json`, 'utf8'));
this.transactionGetConsumption = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/transaction/transaction-get-consumption.json`, 'utf8'));
this.transactionsAssignUser = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/transaction/transactions-assign-user.json`, 'utf8'));
+ this.transactionsUnassignedCountGet = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/transaction/transactions-unassigned-count-user.json`, 'utf8'));
}
public static getInstance(): TransactionValidator {
@@ -67,4 +69,10 @@ export default class TransactionValidator extends SchemaValidator {
this.validate(this.transactionsAssignUser, data);
return data;
}
+
+ public validateTransactionsUnassignedCountReq(data: any): HttpUnassignTransactionsToUserRequest {
+ // Validate schema
+ this.validate(this.transactionsUnassignedCountGet, data);
+ return data;
+ }
}

Added unassigned-transactions-count validation schema