Set Catalog ID at the root of the transaction
MODIFY
src/server/ocpp/services/OCPPService.ts
src/server/ocpp/services/OCPPService.ts
@@ -7,6 +7,7 @@ import Transaction, { InactivityStatus, TransactionAction } from '../../../types
import { Action } from '../../../types/Authorization';
import Authorizations from '../../../authorization/Authorizations';
import BackendError from '../../../exception/BackendError';
+import CarStorage from '../../../storage/mongodb/CarStorage';
import ChargingStationConfiguration from '../../../types/configuration/ChargingStationConfiguration';
import ChargingStationStorage from '../../../storage/mongodb/ChargingStationStorage';
import Configuration from '../../../utils/Configuration';
@@ -665,6 +666,11 @@ export default class OCPPService {
stateOfCharge: 0,
user
};
+ // Set Car Catalog ID
+ if (user.lastSelectedCarID) {
+ const car = await CarStorage.getCar(headers.tenantID, user.lastSelectedCarID, {}, ['id', 'carCatalogID']);
+ transaction.carCatalogID = car?.carCatalogID;
+ }
// Build first Dummy consumption for pricing the Start Transaction
const consumption = await OCPPUtils.createConsumptionFromMeterValue(
headers.tenantID, chargingStation, transaction,

MODIFY
src/server/rest/v1/service/TransactionService.ts
src/server/rest/v1/service/TransactionService.ts
@@ -462,8 +462,8 @@ export default class TransactionService {
if (Utils.isComponentActiveFromToken(req.user, TenantComponents.CAR)) {
projectFields = [
...projectFields,
- 'car.licensePlate', 'car.carCatalog.vehicleMake', 'car.carCatalog.vehicleModel',
- 'car.carCatalog.vehicleModelVersion', 'car.carCatalog.image',
+ 'car.licensePlate', 'carCatalog.vehicleMake', 'carCatalog.vehicleModel',
+ 'carCatalog.vehicleModelVersion', 'carCatalog.image',
];
}
// Get Transaction
@@ -919,7 +919,7 @@ export default class TransactionService {
Authorizations.canListCars(req.user)) {
projectFields = [
...projectFields,
- 'car.licensePlate', 'car.carCatalog.vehicleMake', 'car.carCatalog.vehicleModel', 'car.carCatalog.vehicleModelVersion',
+ 'car.licensePlate', 'carCatalog.vehicleMake', 'carCatalog.vehicleModel', 'carCatalog.vehicleModelVersion',
];
}
// Filter

MODIFY
src/storage/mongodb/CarStorage.ts
src/storage/mongodb/CarStorage.ts
@@ -598,7 +598,8 @@ export default class CarStorage {
}
public static async getCars(tenantID: string,
- params: { search?: string; userIDs?: string[]; carIDs?: string[]; licensePlate?: string; vin?: string; withUsers?: boolean; defaultCar?: boolean; carMakers?: string[] } = {},
+ params: { search?: string; userIDs?: string[]; carIDs?: string[]; licensePlate?: string; vin?: string;
+ withUsers?: boolean; defaultCar?: boolean; carMakers?: string[] } = {},
dbParams?: DbParams, projectFields?: string[]): Promise<DataResult<Car>> {
// Debug
const uniqueTimerID = Logging.traceStart(tenantID, MODULE_NAME, 'getCars');

MODIFY
src/storage/mongodb/TransactionStorage.ts
src/storage/mongodb/TransactionStorage.ts
@@ -57,6 +57,7 @@ export default class TransactionStorage {
connectorId: Utils.convertToInt(transactionToSave.connectorId),
tagID: transactionToSave.tagID,
carID: transactionToSave.carID ? Utils.convertToObjectID(transactionToSave.carID) : null,
+ carCatalogID: transactionToSave.carCatalogID ? Utils.convertToInt(transactionToSave.carCatalogID) : null,
userID: Utils.convertToObjectID(transactionToSave.userID),
chargeBoxID: transactionToSave.chargeBoxID,
meterStart: Utils.convertToInt(transactionToSave.meterStart),
@@ -595,9 +596,10 @@ export default class TransactionStorage {
});
// Car Catalog
DatabaseUtils.pushCarCatalogLookupInAggregation({
- tenantID: Constants.DEFAULT_TENANT, aggregation: aggregation, asField: 'car.carCatalog', localField: 'car.carCatalogID',
+ tenantID: Constants.DEFAULT_TENANT, aggregation: aggregation, asField: 'carCatalog', localField: 'carCatalogID',
foreignField: '_id', oneToOneCardinality: true
});
+ // User
DatabaseUtils.pushUserLookupInAggregation({
tenantID, aggregation: aggregation, asField: 'stop.user', localField: 'stop.userID',
foreignField: '_id', oneToOneCardinality: true, oneToOneCardinalityNotNull: false

MODIFY
src/types/Transaction.ts
src/types/Transaction.ts
+import { Car, CarCatalog } from './Car';
import { ChargePointStatus, OCPP15TransactionData, OCPPMeterValue } from './ocpp/OCPPServer';
import Consumption, { AbstractCurrentConsumption } from './Consumption';
import { BillingTransactionData } from './Billing';
-import { Car } from './Car';
import ChargingStation from '../types/ChargingStation';
import { OCPICdr } from './ocpi/OCPICdr';
import { OCPISession } from './ocpi/OCPISession';
@@ -32,6 +32,8 @@ export default interface Transaction extends AbstractCurrentConsumption {
id?: number;
carID?: string;
car?: Car;
+ carCatalogID?: number;
+ carCatalog?: CarCatalog;
phasesUsed?: CSPhasesUsed;
siteID?: string;
siteAreaID?: string;

Set Catalog ID at the root of the transaction