Handle disable connector when CS is inactive in the backend
MODIFY
src/storage/mongodb/ChargingStationStorage.ts
src/storage/mongodb/ChargingStationStorage.ts
@@ -222,7 +222,7 @@ export default class ChargingStationStorage {
filters.issuer = params.issuer;
}
// Add Charging Station inactive flag
- DatabaseUtils.pushChargingStationInactiveFlag(aggregation);
+ DatabaseUtils.pushChargingStationInactiveFlagInAggregation(aggregation);
// Add in aggregation
aggregation.push({
$match: filters
@@ -364,7 +364,7 @@ export default class ChargingStationStorage {
// Create Aggregation
const aggregation = [];
// Add Charging Station inactive flag
- DatabaseUtils.pushChargingStationInactiveFlag(aggregation);
+ DatabaseUtils.pushChargingStationInactiveFlagInAggregation(aggregation);
// Set the filters
const filters: FilterParams = {};
// Search filters

MODIFY
src/storage/mongodb/DatabaseUtils.ts
src/storage/mongodb/DatabaseUtils.ts
@@ -247,10 +247,12 @@ export default class DatabaseUtils {
}
public static pushChargingStationLookupInAggregation(lookupParams: DbLookup, additionalPipeline: Record<string, any>[] = []): void {
+ // Add Inactive flag
+ DatabaseUtils.pushChargingStationInactiveFlagInAggregation(additionalPipeline);
DatabaseUtils.pushCollectionLookupInAggregation('chargingstations', {
objectIDFields: ['createdBy', 'lastChangedBy'],
...lookupParams
- }, [DatabaseUtils.buildChargingStationInactiveFlagQuery(), ...additionalPipeline]);
+ }, additionalPipeline);
}
public static pushAssetLookupInAggregation(lookupParams: DbLookup, additionalPipeline: Record<string, any>[] = []): void {
@@ -400,11 +402,6 @@ export default class DatabaseUtils {
}
}
- public static pushChargingStationInactiveFlag(aggregation: any[]): void {
- // Add inactive field
- aggregation.push(DatabaseUtils.buildChargingStationInactiveFlagQuery());
- }
-
public static projectFields(aggregation: any[], projectFields: string[], removedFields: string[] = []): void {
if (!Utils.isEmptyArray(projectFields)) {
const project = {
@@ -613,9 +610,9 @@ export default class DatabaseUtils {
aggregation.push({ $replaceRoot: { newRoot: '$root' } });
}
- private static buildChargingStationInactiveFlagQuery(): Record<string, any> {
+ public static pushChargingStationInactiveFlagInAggregation(aggregation: any[]): void {
// Add inactive field
- return {
+ aggregation.push({
$addFields: {
inactive: {
$or: [
@@ -629,7 +626,28 @@ export default class DatabaseUtils {
]
}
}
- };
+ });
+ // Update Connectors' status
+ aggregation.push({
+ $addFields:{
+ connectors: {
+ $map: {
+ input: '$connectors',
+ as: 'connector',
+ in: {
+ $mergeObjects: [
+ '$$connector',
+ { status: { $cond: { if: { $eq: [ '$inactive', true ] }, then: ChargePointStatus.UNAVAILABLE, else: '$$connector.status' } } },
+ { currentInstantWatts: { $cond: { if: { $eq: [ '$inactive', true ] }, then: 0, else: '$$connector.currentInstantWatts' } } },
+ { currentStateOfCharge: { $cond: { if: { $eq: [ '$inactive', true ] }, then: 0, else: '$$connector.currentStateOfCharge' } } },
+ { currentTotalConsumptionWh: { $cond: { if: { $eq: [ '$inactive', true ] }, then: 0, else: '$$connector.currentTotalConsumptionWh' } } },
+ { currentTotalInactivitySecs: { $cond: { if: { $eq: [ '$inactive', true ] }, then: 0, else: '$$connector.currentTotalInactivitySecs' } } },
+ ]
+ }
+ }
+ }
+ }
+ });
}
// Temporary hack to fix user Id saving. fix all this when user is typed...

Handle disable connector when CS is inactive in the backend