Updated Site ID in Charging Profile
MODIFY
src/storage/mongodb/ChargingStationStorage.ts
src/storage/mongodb/ChargingStationStorage.ts
@@ -226,7 +226,7 @@ export default class ChargingStationStorage {
// Site Area
DatabaseUtils.pushSiteAreaLookupInAggregation({
tenantID, aggregation: aggregation, localField: 'siteAreaID', foreignField: '_id',
- asField: 'siteArea', oneToOneCardinality: true, objectIDFields: ['createdBy', 'lastChangedBy']
+ asField: 'siteArea', oneToOneCardinality: true
});
// Check Site ID
if (!Utils.isEmptyArray(params.siteIDs)) {
@@ -706,8 +706,7 @@ export default class ChargingStationStorage {
$match: filters
});
}
-
- if (params.withChargingStation || params.withSiteArea) {
+ if (params.withChargingStation || params.withSiteArea || !Utils.isEmptyArray(params.siteIDs)) {
// Charging Stations
DatabaseUtils.pushChargingStationLookupInAggregation({
tenantID, aggregation, localField: 'chargingStationID', foreignField: '_id',
@@ -718,22 +717,18 @@ export default class ChargingStationStorage {
tenantID, aggregation, localField: 'chargingStation.siteAreaID', foreignField: '_id',
asField: 'chargingStation.siteArea', oneToOneCardinality: true, oneToOneCardinalityNotNull: false
});
- // Convert
- DatabaseUtils.pushConvertObjectIDToString(aggregation, 'chargingStation.siteAreaID');
- DatabaseUtils.pushConvertObjectIDToString(aggregation, 'chargingStation.siteArea.siteID');
// Check Site ID
if (!Utils.isEmptyArray(params.siteIDs)) {
// Build filter
aggregation.push({
$match: {
'chargingStation.siteArea.siteID': {
- $in: params.siteIDs.map((id) => id)
+ $in: params.siteIDs.map((siteID) => Utils.convertToObjectID(siteID))
}
}
});
}
}
-
// Limit records?
if (!dbParams.onlyRecordCount) {
aggregation.push({ $limit: Constants.DB_RECORD_COUNT_CEIL });
@@ -775,6 +770,9 @@ export default class ChargingStationStorage {
aggregation.push({
$limit: dbParams.limit
});
+ // Convert
+ DatabaseUtils.pushConvertObjectIDToString(aggregation, 'chargingStation.siteAreaID');
+ DatabaseUtils.pushConvertObjectIDToString(aggregation, 'chargingStation.siteArea.siteID');
// Project
DatabaseUtils.projectFields(aggregation, projectFields);
// Read DB

MODIFY
src/storage/mongodb/DatabaseUtils.ts
src/storage/mongodb/DatabaseUtils.ts
@@ -95,7 +95,7 @@ export default class DatabaseUtils {
public static pushSiteAreaLookupInAggregation(lookupParams: DbLookup, additionalPipeline: Record<string, any>[] = []): void {
DatabaseUtils.pushCollectionLookupInAggregation('siteareas', {
- objectIDFields: ['siteID', 'createdBy', 'lastChangedBy'],
+ objectIDFields: ['createdBy', 'lastChangedBy'],
...lookupParams
}, additionalPipeline);
}

MODIFY
src/storage/mongodb/TransactionStorage.ts
src/storage/mongodb/TransactionStorage.ts
@@ -800,7 +800,7 @@ export default class TransactionStorage {
// Site Area
DatabaseUtils.pushSiteAreaLookupInAggregation({
tenantID, aggregation: aggregation, localField: 'siteAreaID', foreignField: '_id',
- asField: 'siteArea', oneToOneCardinality: true, objectIDFields: ['createdBy', 'lastChangedBy']
+ asField: 'siteArea', oneToOneCardinality: true
});
}
// Build facets for each type of error if any

Updated Site ID in Charging Profile