Typed convertToObjectID()
MODIFY
src/storage/mongodb/DatabaseUtils.ts
src/storage/mongodb/DatabaseUtils.ts
@@ -371,14 +371,8 @@ export default class DatabaseUtils {
}
}
- public static convertToObjectID(id: any): ObjectId {
- let changedID: ObjectId = id;
- // Check
- if (typeof id === 'string') {
- // Create Object
- changedID = new ObjectId(id);
- }
- return changedID;
+ public static convertToObjectID(id: string): ObjectId {
+ return new ObjectId(id);
}
public static convertUserToObjectID(user: User | UserToken | string): ObjectId | null {

MODIFY
src/storage/mongodb/SiteStorage.ts
src/storage/mongodb/SiteStorage.ts
@@ -306,7 +306,7 @@ export default class SiteStorage {
public static async getSites(tenant: Tenant,
params: {
search?: string; companyIDs?: string[]; withAutoUserAssignment?: boolean; siteIDs?: string[];
- userID?: string; excludeSitesOfUserID?: boolean; issuer?: boolean; public?: boolean; name?: string;
+ userID?: string; excludeSitesOfUserID?: string; issuer?: boolean; public?: boolean; name?: string;
withAvailableChargingStations?: boolean; withOnlyChargingStations?: boolean; withCompany?: boolean;
locCoordinates?: number[]; locMaxDistanceMeters?: number; withImage?: boolean;
} = {},

MODIFY
src/storage/mongodb/TransactionStorage.ts
src/storage/mongodb/TransactionStorage.ts
@@ -407,7 +407,7 @@ export default class TransactionStorage {
// Connector
if (!Utils.isEmptyArray(params.connectorIDs)) {
filters.connectorId = {
- $in: params.connectorIDs.map((connectorID) => DatabaseUtils.convertToObjectID(connectorID))
+ $in: params.connectorIDs
};
}
// Date provided?
@@ -962,7 +962,7 @@ export default class TransactionStorage {
// Connectors
if (!Utils.isEmptyArray(params.connectorIDs)) {
match.connectorId = {
- $in: params.connectorIDs.map((connectorID) => DatabaseUtils.convertToObjectID(connectorID))
+ $in: params.connectorIDs
};
}
// Create Aggregation

MODIFY
src/types/requests/HttpSiteRequest.ts
src/types/requests/HttpSiteRequest.ts
@@ -16,7 +16,7 @@ export interface HttpSitesRequest extends HttpDatabaseRequest {
UserID: string;
CompanyID: string;
SiteID: string;
- ExcludeSitesOfUserID: boolean;
+ ExcludeSitesOfUserID: string;
LocLongitude?: number;
LocLatitude?: number;
LocCoordinates?: number[];

Typed convertToObjectID()