Get default car in start transaction
MODIFY
src/server/ocpp/services/OCPPService.ts
src/server/ocpp/services/OCPPService.ts
@@ -644,7 +644,6 @@ export default class OCPPService {
issuer: true,
chargeBoxID: startTransaction.chargeBoxID,
tagID: startTransaction.idTag,
- carID: user.lastSelectedCarID,
timezone: startTransaction.timezone,
userID: startTransaction.userID,
siteAreaID: startTransaction.siteAreaID,
@@ -667,11 +666,24 @@ export default class OCPPService {
stateOfCharge: 0,
user
};
- // Set Car Catalog ID
+ // Car handling
+ if (Utils.isTenantComponentActive(tenant, TenantComponents.CAR)) {
+ // Check default car
if (user.lastSelectedCarID) {
- const car = await CarStorage.getCar(headers.tenantID, user.lastSelectedCarID, {}, ['id', 'carCatalogID']);
+ transaction.carID = user.lastSelectedCarID;
+ } else {
+ // Get default car if any
+ const defaultCar = await CarStorage.getDefaultUserCar(tenant.id, user.id, {}, ['id']);
+ if (defaultCar) {
+ transaction.carID = defaultCar.id;
+ }
+ }
+ // Set Car Catalog ID
+ if (transaction.carID) {
+ const car = await CarStorage.getCar(headers.tenantID, transaction.carID, {}, ['id', 'carCatalogID']);
transaction.carCatalogID = car?.carCatalogID;
}
+ }
// Build first Dummy consumption for pricing the Start Transaction
const consumption = await OCPPUtils.createConsumptionFromMeterValue(
headers.tenantID, chargingStation, transaction,
@@ -742,6 +754,10 @@ export default class OCPPService {
message: `Connector ID '${transaction.connectorId}' > Transaction ID '${transaction.id}' has been started`
});
}
+ // Clear last user's car selection
+ if (Utils.isTenantComponentActive(tenant, TenantComponents.CAR) && user.lastSelectedCarID) {
+ await UserStorage.saveUserLastSelectedCarID(tenant.id, user.id, null);
+ }
// Return
return {
transactionId: transaction.id,

MODIFY
src/server/rest/v1/service/ChargingStationService.ts
src/server/rest/v1/service/ChargingStationService.ts
@@ -177,9 +177,6 @@ export default class ChargingStationService {
chargingStation.lastChangedBy = { 'id': req.user.id };
chargingStation.lastChangedOn = new Date();
// Update
- console.log('chargingStation ====================================');
- console.log(JSON.stringify(chargingStation, null, ' '));
- console.log('====================================');
await ChargingStationStorage.saveChargingStation(req.user.tenantID, chargingStation);
// Log
Logging.logSecurityInfo({
@@ -1023,11 +1020,14 @@ export default class ChargingStationService {
result = await this.handleChargingStationCommand(
req.user.tenantID, req.user, chargingStation, action, command, filteredRequest.args);
// Save Car ID
+ if (Utils.isComponentActiveFromToken(req.user, TenantComponents.CAR)) {
if (result?.status === OCPPRemoteStartStopStatus.ACCEPTED) {
if (filteredRequest.carID && filteredRequest.carID !== user.lastSelectedCarID) {
+ // Save Car selection
await UserStorage.saveUserLastSelectedCarID(req.user.tenantID, user.id, filteredRequest.carID);
}
}
+ }
} else if (command === Command.GET_COMPOSITE_SCHEDULE) {
// Check auth
if (!Authorizations.canPerformActionOnChargingStation(req.user, command as unknown as Action, chargingStation)) {

Get default car in start transaction