Removed dups IDs in Storage
MODIFY
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/OCPIMapping.ts
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/OCPIMapping.ts
@@ -186,11 +186,14 @@ export default class OCPIMapping {
tokens.push({
uid: tag.id,
type: OCPITokenType.RFID,
+ // eslint-disable-next-line @typescript-eslint/camelcase
auth_id: tag.userID,
+ // eslint-disable-next-line @typescript-eslint/camelcase
visual_number: tag.userID,
issuer: tenant.name,
valid: valid,
whitelist: OCPITokenWhitelist.ALLOWED_OFFLINE,
+ // eslint-disable-next-line @typescript-eslint/camelcase
last_updated: tag.lastChangedOn ? tag.lastChangedOn : new Date()
});
}
@@ -353,6 +356,7 @@ export default class OCPIMapping {
name: site.name,
address: `${site.address.address1} ${site.address.address2}`,
city: site.address.city,
+ // eslint-disable-next-line @typescript-eslint/camelcase
postal_code: site.address.postalCode,
country: site.address.country,
coordinates: {
@@ -362,6 +366,7 @@ export default class OCPIMapping {
type: OCPILocationType.UNKNOWN,
evses: [{
uid: OCPIUtils.buildEvseUID(chargingStation),
+ // eslint-disable-next-line @typescript-eslint/camelcase
evse_id: evseID,
status: OCPIMapping.convertStatus2OCPIStatus(status),
capabilities: [OCPICapability.REMOTE_START_STOP_CAPABLE, OCPICapability.RFID_READER],
@@ -370,8 +375,10 @@ export default class OCPIMapping {
latitude: chargingStation.coordinates[1].toString(),
longitude: chargingStation.coordinates[0].toString()
},
+ // eslint-disable-next-line @typescript-eslint/camelcase
last_updated: chargingStation.lastHeartBeat
}],
+ // eslint-disable-next-line @typescript-eslint/camelcase
last_updated: site.lastChangedOn ? site.lastChangedOn : site.createdOn
};
return ocpiLocation;
@@ -557,6 +564,7 @@ export default class OCPIMapping {
} else {
const consumption: number = transaction.stop ? transaction.stop.totalConsumption : transaction.currentTotalConsumption;
chargingPeriods.push({
+ // eslint-disable-next-line @typescript-eslint/camelcase
start_date_time: transaction.timestamp,
dimensions: [{
type: CdrDimensionType.ENERGY,
@@ -567,6 +575,7 @@ export default class OCPIMapping {
if (inactivity > 0) {
const inactivityStart = transaction.stop ? transaction.stop.timestamp : transaction.lastUpdate;
chargingPeriods.push({
+ // eslint-disable-next-line @typescript-eslint/camelcase
start_date_time: moment(inactivityStart).subtract(inactivity, 'seconds').toDate(),
dimensions: [{
type: CdrDimensionType.PARKING_TIME,
@@ -580,6 +589,7 @@ export default class OCPIMapping {
static buildChargingPeriod(consumption: Consumption): OCPIChargingPeriod {
const chargingPeriod: OCPIChargingPeriod = {
+ // eslint-disable-next-line @typescript-eslint/camelcase
start_date_time: consumption.startedAt,
dimensions: []
};
@@ -635,12 +645,17 @@ export default class OCPIMapping {
if (ocpiSetting && ocpiSetting.ocpi) {
credential.token = token;
if (role === OCPIRole.EMSP) {
+ // eslint-disable-next-line @typescript-eslint/camelcase
credential.country_code = ocpiSetting.ocpi.emsp.countryCode;
+ // eslint-disable-next-line @typescript-eslint/camelcase
credential.party_id = ocpiSetting.ocpi.emsp.partyID;
} else {
+ // eslint-disable-next-line @typescript-eslint/camelcase
credential.country_code = ocpiSetting.ocpi.cpo.countryCode;
+ // eslint-disable-next-line @typescript-eslint/camelcase
credential.party_id = ocpiSetting.ocpi.cpo.partyID;
}
+ // eslint-disable-next-line @typescript-eslint/camelcase
credential.business_details = ocpiSetting.ocpi.businessDetails;
}
// Return credential object

MODIFY
src/server/rest/service/TransactionService.ts
src/server/rest/service/TransactionService.ts
@@ -479,7 +479,7 @@ export default class TransactionService {
filter.siteAreaIDs = filteredRequest.SiteAreaID.split('|');
}
if (filteredRequest.SiteID) {
- filter.siteID = Authorizations.getAuthorizedSiteIDs(req.user, filteredRequest.SiteID.split('|'));
+ filter.siteIDs = Authorizations.getAuthorizedSiteIDs(req.user, filteredRequest.SiteID.split('|'));
}
if (Authorizations.isSiteAdmin(req.user)) {
filter.siteAdminIDs = req.user.sitesAdmin;
@@ -534,7 +534,7 @@ export default class TransactionService {
filter.siteAreaIDs = filteredRequest.SiteAreaID.split('|');
}
if (filteredRequest.SiteID) {
- filter.siteID = Authorizations.getAuthorizedSiteIDs(req.user, filteredRequest.SiteID.split('|'));
+ filter.siteIDs = Authorizations.getAuthorizedSiteIDs(req.user, filteredRequest.SiteID.split('|'));
}
if (Authorizations.isSiteAdmin(req.user)) {
filter.siteAdminIDs = req.user.sitesAdmin;
@@ -861,7 +861,7 @@ export default class TransactionService {
if (filteredRequest.SiteAreaID) {
filter.siteAreaIDs = filteredRequest.SiteAreaID.split('|');
}
- filter.siteID = Authorizations.getAuthorizedSiteAdminIDs(req.user, filteredRequest.SiteID ? filteredRequest.SiteID.split('|') : null);
+ filter.siteIDs = Authorizations.getAuthorizedSiteAdminIDs(req.user, filteredRequest.SiteID ? filteredRequest.SiteID.split('|') : null);
}
// Date
if (filteredRequest.StartDateTime) {

MODIFY
src/storage/mongodb/AssetStorage.ts
src/storage/mongodb/AssetStorage.ts
@@ -19,7 +19,7 @@ export default class AssetStorage {
const assetsMDB = await AssetStorage.getAssets(
tenantID,
{
- assetID: id,
+ assetIDs: [id],
withSiteArea: params.withSiteArea
},
Constants.DB_PARAMS_SINGLE_RECORD
@@ -86,7 +86,7 @@ export default class AssetStorage {
}
public static async getAssets(tenantID: string,
- params: { search?: string; assetID?: string; assetIDs?: string[]; siteAreaIDs?: string[]; withSiteArea?: boolean;
+ params: { search?: string; assetIDs?: string[]; siteAreaIDs?: string[]; withSiteArea?: boolean;
withNoSiteArea?: boolean; } = {},
dbParams?: DbParams, projectFields?: string[]): Promise<DataResult<Asset>> {
// Debug
@@ -100,9 +100,7 @@ export default class AssetStorage {
// Set the filters
const filters: any = {};
// Build filter
- if (params.assetID) {
- filters._id = Utils.convertToObjectID(params.assetID);
- } else if (params.search) {
+ if (params.search) {
const searchRegex = Utils.escapeSpecialCharsInRegex(params.search);
filters.$or = [
{ 'name': { $regex: searchRegex, $options: 'i' } },

MODIFY
src/storage/mongodb/CarStorage.ts
src/storage/mongodb/CarStorage.ts
@@ -18,14 +18,14 @@ export default class CarStorage {
const uniqueTimerID = Logging.traceStart(MODULE_NAME, 'getCarCatalog');
// Query single Site
const carCatalogsMDB = await CarStorage.getCarCatalogs(
- { carCatalogID: Utils.convertToInt(id) },
+ { carCatalogIDs: [id] },
Constants.DB_PARAMS_SINGLE_RECORD, projectFields);
Logging.traceEnd(MODULE_NAME, 'getCarCatalog', uniqueTimerID, { id });
return carCatalogsMDB.count > 0 ? carCatalogsMDB.result[0] : null;
}
public static async getCarCatalogs(
- params: { search?: string; carCatalogID?: number; carCatalogIDs?: number[]; carMaker?: string[] } = {},
+ params: { search?: string; carCatalogIDs?: number[]; carMaker?: string[] } = {},
dbParams?: DbParams, projectFields?: string[]): Promise<DataResult<CarCatalog>> {
// Debug
const uniqueTimerID = Logging.traceStart(MODULE_NAME, 'getCarCatalogs');
@@ -35,9 +35,7 @@ export default class CarStorage {
const skip = Utils.checkRecordSkip(dbParams.skip);
// Set the filters
const filters: ({ _id?: number; $or?: any[] } | undefined) = {};
- if (params.carCatalogID) {
- filters._id = Utils.convertToInt(params.carCatalogID);
- } else if (params.search) {
+ if (params.search) {
const searchRegex = Utils.escapeSpecialCharsInRegex(params.search);
filters.$or = [
{ 'vehicleModel': { $regex: searchRegex, $options: 'i' } },

MODIFY
src/storage/mongodb/ChargingStationStorage.ts
src/storage/mongodb/ChargingStationStorage.ts
@@ -627,9 +627,7 @@ export default class ChargingStationStorage {
await Utils.checkTenant(tenantID);
// Read DB
const parametersMDB = await global.database.getCollection<ChargingStationOcppParameters>(tenantID, 'configurations')
- .findOne({
- '_id': id
- });
+ .findOne({ '_id': id });
// Found?
const parameters: OcppParameter[] = [];
if (parametersMDB && parametersMDB.configuration && parametersMDB.configuration.length > 0) {

MODIFY
src/storage/mongodb/CompanyStorage.ts
src/storage/mongodb/CompanyStorage.ts
@@ -17,7 +17,7 @@ export default class CompanyStorage {
// Debug
const uniqueTimerID = Logging.traceStart(MODULE_NAME, 'getCompany');
// Reuse
- const companiesMDB = await CompanyStorage.getCompanies(tenantID, { companyID: id }, Constants.DB_PARAMS_SINGLE_RECORD);
+ const companiesMDB = await CompanyStorage.getCompanies(tenantID, { companyIDs: [id] }, Constants.DB_PARAMS_SINGLE_RECORD);
let company: Company = null;
// Check
if (companiesMDB && companiesMDB.count > 0) {
@@ -76,7 +76,7 @@ export default class CompanyStorage {
}
public static async getCompanies(tenantID: string,
- params: { search?: string; issuer?: boolean; companyID?: string; companyIDs?: string[]; withSites?: boolean; withLogo?: boolean } = {},
+ params: { search?: string; issuer?: boolean; companyIDs?: string[]; withSites?: boolean; withLogo?: boolean } = {},
dbParams?: DbParams, projectFields?: string[]): Promise<DataResult<Company>> {
// Debug
const uniqueTimerID = Logging.traceStart(MODULE_NAME, 'getCompanies');
@@ -88,10 +88,7 @@ export default class CompanyStorage {
const skip = Utils.checkRecordSkip(dbParams.skip);
// Set the filters
const filters: ({ _id?: ObjectID; $or?: any[] } | undefined) = {};
- // Build filter
- if (params.companyID) {
- filters._id = Utils.convertToObjectID(params.companyID);
- } else if (params.search) {
+ if (params.search) {
const searchRegex = Utils.escapeSpecialCharsInRegex(params.search);
filters.$or = [
{ 'name': { $regex: searchRegex, $options: 'i' } },
@@ -110,7 +107,6 @@ export default class CompanyStorage {
}
});
}
-
if (params.issuer === true || params.issuer === false) {
aggregation.push({
$match: {

MODIFY
src/storage/mongodb/SiteStorage.ts
src/storage/mongodb/SiteStorage.ts
@@ -22,7 +22,7 @@ export default class SiteStorage {
const uniqueTimerID = Logging.traceStart(MODULE_NAME, 'getSite');
// Query single Site
const sitesMDB = await SiteStorage.getSites(tenantID,
- { siteID: id, withCompany: params.withCompany },
+ { siteIDs: [id], withCompany: params.withCompany },
Constants.DB_PARAMS_SINGLE_RECORD);
// Debug
Logging.traceEnd(MODULE_NAME, 'getSite', uniqueTimerID, { id });
@@ -308,7 +308,7 @@ export default class SiteStorage {
public static async getSites(tenantID: string,
params: {
search?: string; companyIDs?: string[]; withAutoUserAssignment?: boolean; siteIDs?: string[];
- userID?: string; excludeSitesOfUserID?: boolean; siteID?: string; issuer?: boolean;
+ userID?: string; excludeSitesOfUserID?: boolean; issuer?: boolean;
withAvailableChargers?: boolean; withCompany?: boolean;
} = {},
dbParams: DbParams, projectFields?: string[]): Promise<DataResult<Site>> {
@@ -324,9 +324,7 @@ export default class SiteStorage {
const aggregation = [];
// Search filters
const filters: any = {};
- if (params.siteID) {
- filters._id = Utils.convertToObjectID(params.siteID);
- } else if (params.search) {
+ if (params.search) {
filters.$or = [
{ 'name': { $regex: Utils.escapeSpecialCharsInRegex(params.search), $options: 'i' } }
];

MODIFY
src/storage/mongodb/TransactionStorage.ts
src/storage/mongodb/TransactionStorage.ts
@@ -233,7 +233,7 @@ export default class TransactionStorage {
public static async getTransactions(tenantID: string,
params: {
transactionId?: number; issuer?: boolean; search?: string; ownerID?: string; userIDs?: string[]; siteAdminIDs?: string[];
- chargeBoxIDs?: string[]; siteAreaIDs?: string[]; siteID?: string[]; connectorId?: number; startDateTime?: Date;
+ chargeBoxIDs?: string[]; siteAreaIDs?: string[]; siteIDs?: string[]; connectorId?: number; startDateTime?: Date;
endDateTime?: Date; stop?: any; minimalPrice?: boolean; reportIDs?: string[]; inactivityStatus?: InactivityStatus[];
ocpiSessionId?: string; ocpiSessionDateFrom?: Date; ocpiSessionDateTo?: Date; ocpiCdrDateFrom?: Date; ocpiCdrDateTo?: Date;
ocpiSessionChecked?: boolean; ocpiCdrChecked?: boolean;
@@ -360,9 +360,9 @@ export default class TransactionStorage {
};
}
// Site ID
- if (params.siteID) {
+ if (params.siteIDs) {
filterMatch.siteID = {
- $in: params.siteID.map((siteID) => Utils.convertToObjectID(siteID))
+ $in: params.siteIDs.map((siteID) => Utils.convertToObjectID(siteID))
};
}
// Refund status
@@ -583,7 +583,9 @@ export default class TransactionStorage {
};
}
- public static async getRefundReports(tenantID: string, filter: { ownerID?: string; siteAdminIDs?: string[] }, dbParams: DbParams, projectFields?: string[]): Promise<{ count: number; result: RefundReport[]; stats: {} }> {
+ public static async getRefundReports(tenantID: string,
+ params: { ownerID?: string; siteAdminIDs?: string[] },
+ dbParams: DbParams, projectFields?: string[]): Promise<{ count: number; result: RefundReport[]; stats: {} }> {
// Debug
const uniqueTimerID = Logging.traceStart(MODULE_NAME, 'getTransactions');
// Check
@@ -598,15 +600,15 @@ export default class TransactionStorage {
const filterMatch = {};
filterMatch['refundData.reportId'] = { '$ne': null };
- if (filter.ownerID) {
+ if (params.ownerID) {
ownerMatch.$or.push({
- userID: Utils.convertToObjectID(filter.ownerID)
+ userID: Utils.convertToObjectID(params.ownerID)
});
}
- if (filter.siteAdminIDs) {
+ if (params.siteAdminIDs) {
ownerMatch.$or.push({
siteID: {
- $in: filter.siteAdminIDs.map((siteID) => Utils.convertToObjectID(siteID))
+ $in: params.siteAdminIDs.map((siteID) => Utils.convertToObjectID(siteID))
}
});
}
@@ -721,7 +723,7 @@ export default class TransactionStorage {
static async getTransactionsInError(tenantID,
params: {
search?: string; issuer?: boolean; userIDs?: string[]; chargeBoxIDs?: string[];
- siteAreaIDs?: string[]; siteID?: string[]; startDateTime?: Date; endDateTime?: Date; withChargeBoxes?: boolean;
+ siteAreaIDs?: string[]; siteIDs?: string[]; startDateTime?: Date; endDateTime?: Date; withChargeBoxes?: boolean;
errorType?: (TransactionInErrorType.LONG_INACTIVITY | TransactionInErrorType.NEGATIVE_ACTIVITY | TransactionInErrorType.NEGATIVE_DURATION | TransactionInErrorType.OVER_CONSUMPTION | TransactionInErrorType.INVALID_START_DATE | TransactionInErrorType.NO_CONSUMPTION | TransactionInErrorType.MISSING_USER | TransactionInErrorType.MISSING_PRICE)[];
},
dbParams: DbParams, projectFields?: string[]): Promise<DataResult<TransactionInError>> {
@@ -774,9 +776,9 @@ export default class TransactionStorage {
};
}
// Sites
- if (params.siteID) {
+ if (params.siteIDs) {
match.siteID = {
- $in: params.siteID.map((site) => Utils.convertToObjectID(site))
+ $in: params.siteIDs.map((site) => Utils.convertToObjectID(site))
};
}
// Create Aggregation

MODIFY
src/storage/mongodb/UserStorage.ts
src/storage/mongodb/UserStorage.ts
@@ -697,7 +697,9 @@ export default class UserStorage {
return tag.count > 0 ? tag.result[0] : null;
}
- public static async getTags(tenantID: string, params: { issuer?: boolean; tagID?: string; userID?: string; dateFrom?: Date; dateTo?: Date }, dbParams: DbParams): Promise<DataResult<Tag>> {
+ public static async getTags(tenantID: string,
+ params: { issuer?: boolean; tagID?: string; userID?: string; dateFrom?: Date; dateTo?: Date },
+ dbParams: DbParams): Promise<DataResult<Tag>> {
const uniqueTimerID = Logging.traceStart(MODULE_NAME, 'getTags');
// Check Tenant
await Utils.checkTenant(tenantID);

Removed dups IDs in Storage