Fixed transactions in error sorting
MODIFY
src/server/rest/v1/service/TransactionService.ts
src/server/rest/v1/service/TransactionService.ts
@@ -879,7 +879,13 @@ export default class TransactionService {
siteIDs: Authorizations.getAuthorizedSiteAdminIDs(req.user, filteredRequest.SiteID ? filteredRequest.SiteID.split('|') : null),
userIDs: filteredRequest.UserID ? filteredRequest.UserID.split('|') : null,
connectorIDs: filteredRequest.ConnectorID ? filteredRequest.ConnectorID.split('|').map((connectorID) => Utils.convertToInt(connectorID)) : null,
- }, [
+ },
+ {
+ limit: filteredRequest.Limit,
+ skip: filteredRequest.Skip,
+ sort: filteredRequest.SortFields
+ },
+ [
'id', 'chargeBoxID', 'timestamp', 'issuer', 'stateOfCharge', 'timezone', 'connectorId',
'meterStart', 'siteAreaID', 'siteID', 'errorCode', 'uniqueId'
]);

MODIFY
src/storage/mongodb/TransactionStorage.ts
src/storage/mongodb/TransactionStorage.ts
@@ -795,11 +795,17 @@ export default class TransactionStorage {
search?: string; issuer?: boolean; userIDs?: string[]; chargeBoxIDs?: string[];
siteAreaIDs?: string[]; siteIDs?: string[]; startDateTime?: Date; endDateTime?: Date;
withChargeBoxes?: boolean; errorType?: TransactionInErrorType[]; connectorIDs?: number[];
- }, projectFields?: string[]): Promise<DataResult<TransactionInError>> {
+ }, dbParams: DbParams, projectFields?: string[]): Promise<DataResult<TransactionInError>> {
// Debug
const uniqueTimerID = Logging.traceStart(tenantID, MODULE_NAME, 'getTransactionsInError');
// Check
await DatabaseUtils.checkTenant(tenantID);
+ // Clone before updating the values
+ dbParams = Utils.cloneObject(dbParams);
+ // Check Limit
+ dbParams.limit = Utils.checkRecordLimit(dbParams.limit);
+ // Check Skip
+ dbParams.skip = Utils.checkRecordSkip(dbParams.skip);
// Build filters
const match: any = { stop: { $exists: true } };
// Filter?
@@ -912,6 +918,21 @@ export default class TransactionStorage {
// Set to null
DatabaseUtils.clearFieldValueIfSubFieldIsNull(aggregation, 'stop', 'timestamp');
DatabaseUtils.clearFieldValueIfSubFieldIsNull(aggregation, 'remotestop', 'timestamp');
+ // Sort
+ if (!dbParams.sort) {
+ dbParams.sort = { _id: 1 };
+ }
+ aggregation.push({
+ $sort: dbParams.sort
+ });
+ // Skip
+ aggregation.push({
+ $skip: dbParams.skip
+ });
+ // Limit
+ aggregation.push({
+ $limit: dbParams.limit
+ });
// Project
DatabaseUtils.projectFields(aggregation, projectFields);
// Read DB

Fixed transactions in error sorting