add connector filter to transactions list
MODIFY
src/server/rest/v1/service/ChargingStationService.ts
src/server/rest/v1/service/ChargingStationService.ts
@@ -1290,7 +1290,6 @@ export default class ChargingStationService {
chargingStationIDs: filteredRequest.ChargeBoxID ? filteredRequest.ChargeBoxID.split('|') : null,
connectorStatuses: filteredRequest.ConnectorStatus ? filteredRequest.ConnectorStatus.split('|') : null,
connectorTypes: filteredRequest.ConnectorType ? filteredRequest.ConnectorType.split('|') : null,
- connectorIDs: filteredRequest.ConnectorID ? filteredRequest.ConnectorID.split('|').map((connectorID) => Utils.convertToInt(connectorID)) : null,
issuer: filteredRequest.Issuer,
siteIDs: Authorizations.getAuthorizedSiteIDs(req.user, filteredRequest.SiteID ? filteredRequest.SiteID.split('|') : null),
siteAreaIDs: filteredRequest.SiteAreaID ? filteredRequest.SiteAreaID.split('|') : null,

MODIFY
src/server/rest/v1/service/TransactionService.ts
src/server/rest/v1/service/TransactionService.ts
@@ -835,7 +835,10 @@ export default class TransactionService {
}
// Site Area
const transactions = await TransactionStorage.getTransactionsInError(req.user.tenantID,
- { ...filter, search: filteredRequest.Search }, [
+ {
+ ...filter, search: filteredRequest.Search,
+ connectorIDs: filteredRequest.ConnectorID ? filteredRequest.ConnectorID.split('|').map((connectorID) => Utils.convertToInt(connectorID)) : null,
+ }, [
'id', 'chargeBoxID', 'timestamp', 'issuer', 'stateOfCharge', 'timezone', 'connectorId',
'meterStart', 'siteAreaID', 'siteID', 'errorCode', 'uniqueId'
]);
@@ -1011,7 +1014,7 @@ export default class TransactionService {
statistics: filteredRequest.Statistics ? filteredRequest.Statistics : null,
search: filteredRequest.Search ? filteredRequest.Search : null,
reportIDs: filteredRequest.ReportIDs ? filteredRequest.ReportIDs.split('|') : null,
- connectorId: filteredRequest.ConnectorId ? filteredRequest.ConnectorId : null,
+ connectorIDs: filteredRequest.ConnectorID ? filteredRequest.ConnectorID.split('|').map((connectorID) => Utils.convertToInt(connectorID)) : null,
inactivityStatus: filteredRequest.InactivityStatus ? filteredRequest.InactivityStatus.split('|') : null,
},
{ limit: filteredRequest.Limit, skip: filteredRequest.Skip, sort: filteredRequest.Sort, onlyRecordCount: filteredRequest.OnlyRecordCount },

MODIFY
src/server/rest/v1/service/security/ChargingStationSecurity.ts
src/server/rest/v1/service/security/ChargingStationSecurity.ts
@@ -87,7 +87,6 @@ export default class ChargingStationSecurity {
filteredRequest.SiteID = sanitize(request.SiteID);
filteredRequest.WithSite = UtilsSecurity.filterBoolean(request.WithSite);
filteredRequest.SiteAreaID = sanitize(request.SiteAreaID);
- filteredRequest.ConnectorID = sanitize(request.ConnectorID);
filteredRequest.ConnectorStatus = sanitize(request.ConnectorStatus);
filteredRequest.ConnectorType = sanitize(request.ConnectorType);
filteredRequest.ChargeBoxID = sanitize(request.ChargeBoxID);

MODIFY
src/server/rest/v1/service/security/TransactionSecurity.ts
src/server/rest/v1/service/security/TransactionSecurity.ts
@@ -49,22 +49,6 @@ export default class TransactionSecurity {
};
}
- public static filterTransactionsActiveRequest(request: any): HttpTransactionsRequest {
- const filteredRequest: HttpTransactionsRequest = {} as HttpTransactionsRequest;
- if (request.Issuer) {
- filteredRequest.Issuer = UtilsSecurity.filterBoolean(request.Issuer);
- }
- filteredRequest.ChargeBoxID = sanitize(request.ChargeBoxID);
- filteredRequest.ConnectorId = sanitize(request.ConnectorId);
- filteredRequest.SiteAreaID = sanitize(request.SiteAreaID);
- filteredRequest.Search = sanitize(request.Search);
- filteredRequest.SiteID = sanitize(request.SiteID);
- filteredRequest.UserID = request.UserID ? sanitize(request.UserID) : null;
- UtilsSecurity.filterSkipAndLimit(request, filteredRequest);
- UtilsSecurity.filterSort(request, filteredRequest);
- return filteredRequest;
- }
-
public static filterTransactionsRequest(request: any): HttpTransactionsRequest {
const filteredRequest = {} as HttpTransactionsRequest;
// Handle picture
@@ -81,6 +65,7 @@ export default class TransactionSecurity {
filteredRequest.InactivityStatus = sanitize(request.InactivityStatus);
filteredRequest.RefundStatus = sanitize(request.RefundStatus);
filteredRequest.MinimalPrice = sanitize(request.MinimalPrice);
+ filteredRequest.ConnectorID = sanitize(request.ConnectorID);
if (request.Statistics) {
filteredRequest.Statistics = sanitize(request.Statistics);
}
@@ -105,6 +90,7 @@ export default class TransactionSecurity {
filteredRequest.SiteAreaID = sanitize(request.SiteAreaID);
filteredRequest.Search = sanitize(request.Search);
filteredRequest.ErrorType = sanitize(request.ErrorType);
+ filteredRequest.ConnectorID = sanitize(request.ConnectorID);
if (request.UserID) {
filteredRequest.UserID = sanitize(request.UserID);
}
@@ -124,16 +110,4 @@ export default class TransactionSecurity {
}
return filteredRequest;
}
-
- public static filterChargingStationTransactionsRequest(request: any): HttpTransactionsRequest {
- const filteredRequest: HttpTransactionsRequest = {} as HttpTransactionsRequest;
- // Set
- filteredRequest.ChargeBoxID = sanitize(request.ChargeBoxID);
- filteredRequest.ConnectorId = sanitize(request.ConnectorId);
- filteredRequest.StartDateTime = sanitize(request.StartDateTime);
- filteredRequest.EndDateTime = sanitize(request.EndDateTime);
- UtilsSecurity.filterSkipAndLimit(request, filteredRequest);
- UtilsSecurity.filterSort(request, filteredRequest);
- return filteredRequest;
- }
}

MODIFY
src/storage/mongodb/ChargingStationStorage.ts
src/storage/mongodb/ChargingStationStorage.ts
@@ -146,7 +146,7 @@ export default class ChargingStationStorage {
search?: string; chargingStationIDs?: string[]; siteAreaIDs?: string[]; withNoSiteArea?: boolean;
connectorStatuses?: string[]; connectorTypes?: string[]; statusChangedBefore?: Date;
siteIDs?: string[]; withSite?: boolean; includeDeleted?: boolean; offlineSince?: Date; issuer?: boolean;
- locCoordinates?: number[]; locMaxDistanceMeters?: number; connectorIDs?: number[];
+ locCoordinates?: number[]; locMaxDistanceMeters?: number;
},
dbParams: DbParams, projectFields?: string[]): Promise<DataResult<ChargingStation>> {
// Debug
@@ -213,23 +213,6 @@ export default class ChargingStationStorage {
aggregation.push({
$match: filters
});
- // Connector ID
- if (!Utils.isEmptyArray(params.connectorIDs)) {
- filters['connectors.connectorId'] = { $in: params.connectorIDs };
- aggregation.push({
- '$addFields': {
- 'connectors': {
- '$filter': {
- input: '$connectors',
- as: 'connector',
- cond: {
- $in: ['$$connector.connectorId', params.connectorIDs]
- }
- }
- }
- }
- });
- }
// Connector Status
if (params.connectorStatuses) {
filters['connectors.status'] = { $in: params.connectorStatuses };

MODIFY
src/storage/mongodb/TransactionStorage.ts
src/storage/mongodb/TransactionStorage.ts
@@ -257,7 +257,7 @@ export default class TransactionStorage {
public static async getTransactions(tenantID: string,
params: {
transactionIDs?: number[]; issuer?: boolean; search?: string; ownerID?: string; userIDs?: string[]; siteAdminIDs?: string[];
- chargeBoxIDs?: string[]; siteAreaIDs?: string[]; siteIDs?: string[]; connectorId?: number; startDateTime?: Date;
+ chargeBoxIDs?: string[]; siteAreaIDs?: string[]; siteIDs?: string[]; connectorIDs?: number[]; startDateTime?: Date;
endDateTime?: Date; stop?: any; minimalPrice?: boolean; reportIDs?: string[]; tagIDs?: string[]; inactivityStatus?: string[];
ocpiSessionID?: string; ocpiSessionDateFrom?: Date; ocpiSessionDateTo?: Date; ocpiCdrDateFrom?: Date; ocpiCdrDateTo?: Date;
ocpiSessionChecked?: boolean; ocpiCdrChecked?: boolean;
@@ -334,8 +334,10 @@ export default class TransactionStorage {
filters.tagID = { $in: params.tagIDs };
}
// Connector
- if (params.connectorId) {
- filters.connectorId = Utils.convertToInt(params.connectorId);
+ if (!Utils.isEmptyArray(params.connectorIDs)) {
+ filters.connectorId = {
+ $in: params.connectorIDs.map((connectorID) => Utils.convertToObjectID(connectorID))
+ };
}
// Date provided?
if (params.startDateTime || params.endDateTime) {
@@ -774,7 +776,7 @@ export default class TransactionStorage {
params: {
search?: string; issuer?: boolean; userIDs?: string[]; chargeBoxIDs?: string[];
siteAreaIDs?: string[]; siteIDs?: string[]; startDateTime?: Date; endDateTime?: Date;
- withChargeBoxes?: boolean; errorType?: TransactionInErrorType[];
+ withChargeBoxes?: boolean; errorType?: TransactionInErrorType[]; connectorIDs?: number[];
}, projectFields?: string[]): Promise<DataResult<TransactionInError>> {
// Debug
const uniqueTimerID = Logging.traceStart(tenantID, MODULE_NAME, 'getTransactionsInError');
@@ -826,6 +828,12 @@ export default class TransactionStorage {
$in: params.siteIDs.map((site) => Utils.convertToObjectID(site))
};
}
+ // Connectors
+ if (!Utils.isEmptyArray(params.connectorIDs)) {
+ match.connectorId = {
+ $in: params.connectorIDs.map((connectorID) => Utils.convertToObjectID(connectorID))
+ };
+ }
// Create Aggregation
const aggregation = [];
aggregation.push({

MODIFY
src/types/requests/HttpChargingStationRequest.ts
src/types/requests/HttpChargingStationRequest.ts
@@ -43,7 +43,6 @@ export interface HttpChargingStationsRequest extends HttpDatabaseRequest {
ErrorType?: string;
LocCoordinates?: number[];
LocMaxDistanceMeters?: number;
- ConnectorID?: string;
}
export interface HttpChargingStationParamsUpdateRequest {

MODIFY
src/types/requests/HttpTransactionRequest.ts
src/types/requests/HttpTransactionRequest.ts
@@ -24,7 +24,7 @@ export interface HttpPushTransactionCdrRequest {
export interface HttpTransactionsRequest extends HttpDatabaseRequest {
ChargeBoxID: string;
Issuer: boolean;
- ConnectorId: number;
+ ConnectorID: string;
SiteAreaID?: string;
SiteID?: string;
UserID?: string;

add connector filter to transactions list