Change Tenant ID to Object TenantStorage
MODIFY
src/notification/NotificationHandler.ts
src/notification/NotificationHandler.ts
-import Tenant, { TenantLogo } from '../types/Tenant';
import User, { UserRole } from '../types/User';
-import UserNotifications, { AccountVerificationNotification, AdminAccountVerificationNotification, BillingInvoiceSynchronizationFailedNotification, BillingNewInvoiceNotification, BillingUserSynchronizationFailedNotification, CarCatalogSynchronizationFailedNotification, ChargingStationRegisteredNotification, ChargingStationStatusErrorNotification, ComputeAndApplyChargingProfilesFailedNotification, EndOfChargeNotification, EndOfSessionNotification, EndOfSignedSessionNotification, EndUserErrorNotification, NewRegisteredUserNotification, Notification, NotificationSeverity, NotificationSource, OCPIPatchChargingStationsStatusesErrorNotification, OICPPatchChargingStationsErrorNotification, OICPPatchChargingStationsStatusesErrorNotification, OfflineChargingStationNotification, OptimalChargeReachedNotification, PreparingSessionNotStartedNotification, RequestPasswordNotification, SessionNotStartedNotification, SmtpErrorNotification, TransactionStartedNotification, UnknownUserBadgedNotification, UserAccountInactivityNotification, UserAccountStatusChangedNotification, UserCreatePassword, UserNotificationKeys, VerificationEmailNotification } from '../types/UserNotifications';
+import UserNotifications, { AccountVerificationNotification, AdminAccountVerificationNotification, BillingInvoiceSynchronizationFailedNotification, BillingNewInvoiceNotification, BillingUserSynchronizationFailedNotification, CarCatalogSynchronizationFailedNotification, ChargingStationRegisteredNotification, ChargingStationStatusErrorNotification, ComputeAndApplyChargingProfilesFailedNotification, EndOfChargeNotification, EndOfSessionNotification, EndOfSignedSessionNotification, EndUserErrorNotification, NewRegisteredUserNotification, NotificationSeverity, NotificationSource, OCPIPatchChargingStationsStatusesErrorNotification, OICPPatchChargingStationsErrorNotification, OICPPatchChargingStationsStatusesErrorNotification, OfflineChargingStationNotification, OptimalChargeReachedNotification, PreparingSessionNotStartedNotification, RequestPasswordNotification, SessionNotStartedNotification, SmtpErrorNotification, TransactionStartedNotification, UnknownUserBadgedNotification, UserAccountInactivityNotification, UserAccountStatusChangedNotification, UserCreatePassword, UserNotificationKeys, VerificationEmailNotification } from '../types/UserNotifications';
import ChargingStation from '../types/ChargingStation';
import Configuration from '../utils/Configuration';
@@ -10,6 +9,7 @@ import Logging from '../utils/Logging';
import NotificationStorage from '../storage/mongodb/NotificationStorage';
import RemotePushNotificationTask from './remote-push-notification/RemotePushNotificationTask';
import { ServerAction } from '../types/Server';
+import Tenant from '../types/Tenant';
import TenantStorage from '../storage/mongodb/TenantStorage';
import UserStorage from '../storage/mongodb/UserStorage';
import Utils from '../utils/Utils';
@@ -95,7 +95,7 @@ export default class NotificationHandler {
if (tenant.id !== Constants.DEFAULT_TENANT) {
// Get the Tenant logo
if (Utils.isNullOrUndefined(tenant.logo) || tenant.logo === '') {
- const tenantLogo = await TenantStorage.getTenantLogo(tenant.id);
+ const tenantLogo = await TenantStorage.getTenantLogo(tenant);
tenant.logo = tenantLogo.logo;
}
sourceData.tenantLogoURL = tenant.logo;
@@ -137,7 +137,7 @@ export default class NotificationHandler {
if (tenant.id !== Constants.DEFAULT_TENANT) {
// Get the Tenant logo
if (Utils.isNullOrUndefined(tenant.logo) || tenant.logo === '') {
- const tenantLogo = await TenantStorage.getTenantLogo(tenant.id);
+ const tenantLogo = await TenantStorage.getTenantLogo(tenant);
tenant.logo = tenantLogo.logo;
}
sourceData.tenantLogoURL = tenant.logo;
@@ -179,7 +179,7 @@ export default class NotificationHandler {
if (tenant.id !== Constants.DEFAULT_TENANT) {
// Get the Tenant logo
if (Utils.isNullOrUndefined(tenant.logo) || tenant.logo === '') {
- const tenantLogo = await TenantStorage.getTenantLogo(tenant.id);
+ const tenantLogo = await TenantStorage.getTenantLogo(tenant);
tenant.logo = tenantLogo.logo;
}
sourceData.tenantLogoURL = tenant.logo;
@@ -221,7 +221,7 @@ export default class NotificationHandler {
if (tenant.id !== Constants.DEFAULT_TENANT) {
// Get the Tenant logo
if (Utils.isNullOrUndefined(tenant.logo) || tenant.logo === '') {
- const tenantLogo = await TenantStorage.getTenantLogo(tenant.id);
+ const tenantLogo = await TenantStorage.getTenantLogo(tenant);
tenant.logo = tenantLogo.logo;
}
sourceData.tenantLogoURL = tenant.logo;
@@ -263,7 +263,7 @@ export default class NotificationHandler {
if (tenant.id !== Constants.DEFAULT_TENANT) {
// Get the Tenant logo
if (Utils.isNullOrUndefined(tenant.logo) || tenant.logo === '') {
- const tenantLogo = await TenantStorage.getTenantLogo(tenant.id);
+ const tenantLogo = await TenantStorage.getTenantLogo(tenant);
tenant.logo = tenantLogo.logo;
}
sourceData.tenantLogoURL = tenant.logo;
@@ -291,7 +291,7 @@ export default class NotificationHandler {
if (tenant.id !== Constants.DEFAULT_TENANT) {
// Get the Tenant logo
if (Utils.isNullOrUndefined(tenant.logo) || tenant.logo === '') {
- const tenantLogo = await TenantStorage.getTenantLogo(tenant.id);
+ const tenantLogo = await TenantStorage.getTenantLogo(tenant);
tenant.logo = tenantLogo.logo;
}
sourceData.tenantLogoURL = tenant.logo;
@@ -322,7 +322,7 @@ export default class NotificationHandler {
if (tenant.id !== Constants.DEFAULT_TENANT) {
// Get the Tenant logo
if (Utils.isNullOrUndefined(tenant.logo) || tenant.logo === '') {
- const tenantLogo = await TenantStorage.getTenantLogo(tenant.id);
+ const tenantLogo = await TenantStorage.getTenantLogo(tenant);
tenant.logo = tenantLogo.logo;
}
sourceData.tenantLogoURL = tenant.logo;
@@ -349,7 +349,7 @@ export default class NotificationHandler {
if (tenant.id !== Constants.DEFAULT_TENANT) {
// Get the Tenant logo
if (Utils.isNullOrUndefined(tenant.logo) || tenant.logo === '') {
- const tenantLogo = await TenantStorage.getTenantLogo(tenant.id);
+ const tenantLogo = await TenantStorage.getTenantLogo(tenant);
tenant.logo = tenantLogo.logo;
}
sourceData.tenantLogoURL = tenant.logo;
@@ -387,7 +387,7 @@ export default class NotificationHandler {
if (tenant.id !== Constants.DEFAULT_TENANT) {
// Get the Tenant logo
if (Utils.isNullOrUndefined(tenant.logo) || tenant.logo === '') {
- const tenantLogo = await TenantStorage.getTenantLogo(tenant.id);
+ const tenantLogo = await TenantStorage.getTenantLogo(tenant);
tenant.logo = tenantLogo.logo;
}
adminSourceData.tenantLogoURL = tenant.logo;
@@ -420,7 +420,7 @@ export default class NotificationHandler {
if (tenant.id !== Constants.DEFAULT_TENANT) {
// Get the Tenant logo
if (Utils.isNullOrUndefined(tenant.logo) || tenant.logo === '') {
- const tenantLogo = await TenantStorage.getTenantLogo(tenant.id);
+ const tenantLogo = await TenantStorage.getTenantLogo(tenant);
tenant.logo = tenantLogo.logo;
}
sourceData.tenantLogoURL = tenant.logo;
@@ -473,7 +473,7 @@ export default class NotificationHandler {
if (tenant.id !== Constants.DEFAULT_TENANT) {
// Get the Tenant logo
if (Utils.isNullOrUndefined(tenant.logo) || tenant.logo === '') {
- const tenantLogo = await TenantStorage.getTenantLogo(tenant.id);
+ const tenantLogo = await TenantStorage.getTenantLogo(tenant);
tenant.logo = tenantLogo.logo;
}
sourceData.tenantLogoURL = tenant.logo;
@@ -514,7 +514,7 @@ export default class NotificationHandler {
if (tenant.id !== Constants.DEFAULT_TENANT) {
// Get the Tenant logo
if (Utils.isNullOrUndefined(tenant.logo) || tenant.logo === '') {
- const tenantLogo = await TenantStorage.getTenantLogo(tenant.id);
+ const tenantLogo = await TenantStorage.getTenantLogo(tenant);
tenant.logo = tenantLogo.logo;
}
sourceData.tenantLogoURL = tenant.logo;
@@ -548,7 +548,7 @@ export default class NotificationHandler {
if (tenant.id !== Constants.DEFAULT_TENANT) {
// Get the Tenant logo
if (Utils.isNullOrUndefined(tenant.logo) || tenant.logo === '') {
- const tenantLogo = await TenantStorage.getTenantLogo(tenant.id);
+ const tenantLogo = await TenantStorage.getTenantLogo(tenant);
tenant.logo = tenantLogo.logo;
}
sourceData.tenantLogoURL = tenant.logo;
@@ -582,7 +582,7 @@ export default class NotificationHandler {
if (tenant.id !== Constants.DEFAULT_TENANT) {
// Get the Tenant logo
if (Utils.isNullOrUndefined(tenant.logo) || tenant.logo === '') {
- const tenantLogo = await TenantStorage.getTenantLogo(tenant.id);
+ const tenantLogo = await TenantStorage.getTenantLogo(tenant);
tenant.logo = tenantLogo.logo;
}
sourceData.tenantLogoURL = tenant.logo;
@@ -625,7 +625,7 @@ export default class NotificationHandler {
if (tenant.id !== Constants.DEFAULT_TENANT) {
// Get the Tenant logo
if (Utils.isNullOrUndefined(tenant.logo) || tenant.logo === '') {
- const tenantLogo = await TenantStorage.getTenantLogo(tenant.id);
+ const tenantLogo = await TenantStorage.getTenantLogo(tenant);
tenant.logo = tenantLogo.logo;
}
sourceData.tenantLogoURL = tenant.logo;
@@ -667,7 +667,7 @@ export default class NotificationHandler {
if (tenant.id !== Constants.DEFAULT_TENANT) {
// Get the Tenant logo
if (Utils.isNullOrUndefined(tenant.logo) || tenant.logo === '') {
- const tenantLogo = await TenantStorage.getTenantLogo(tenant.id);
+ const tenantLogo = await TenantStorage.getTenantLogo(tenant);
tenant.logo = tenantLogo.logo;
}
sourceData.tenantLogoURL = tenant.logo;
@@ -715,7 +715,7 @@ export default class NotificationHandler {
if (tenant.id !== Constants.DEFAULT_TENANT) {
// Get the Tenant logo
if (Utils.isNullOrUndefined(tenant.logo) || tenant.logo === '') {
- const tenantLogo = await TenantStorage.getTenantLogo(tenant.id);
+ const tenantLogo = await TenantStorage.getTenantLogo(tenant);
tenant.logo = tenantLogo.logo;
}
sourceData.tenantLogoURL = tenant.logo;
@@ -758,7 +758,7 @@ export default class NotificationHandler {
if (tenant.id !== Constants.DEFAULT_TENANT) {
// Get the Tenant logo
if (Utils.isNullOrUndefined(tenant.logo) || tenant.logo === '') {
- const tenantLogo = await TenantStorage.getTenantLogo(tenant.id);
+ const tenantLogo = await TenantStorage.getTenantLogo(tenant);
tenant.logo = tenantLogo.logo;
}
sourceData.tenantLogoURL = tenant.logo;
@@ -801,7 +801,7 @@ export default class NotificationHandler {
if (tenant.id !== Constants.DEFAULT_TENANT) {
// Get the Tenant logo
if (Utils.isNullOrUndefined(tenant.logo) || tenant.logo === '') {
- const tenantLogo = await TenantStorage.getTenantLogo(tenant.id);
+ const tenantLogo = await TenantStorage.getTenantLogo(tenant);
tenant.logo = tenantLogo.logo;
}
sourceData.tenantLogoURL = tenant.logo;
@@ -834,7 +834,7 @@ export default class NotificationHandler {
if (tenant.id !== Constants.DEFAULT_TENANT) {
// Get the Tenant logo
if (Utils.isNullOrUndefined(tenant.logo) || tenant.logo === '') {
- const tenantLogo = await TenantStorage.getTenantLogo(tenant.id);
+ const tenantLogo = await TenantStorage.getTenantLogo(tenant);
tenant.logo = tenantLogo.logo;
}
sourceData.tenantLogoURL = tenant.logo;
@@ -876,7 +876,7 @@ export default class NotificationHandler {
if (tenant.id !== Constants.DEFAULT_TENANT) {
// Get the Tenant logo
if (Utils.isNullOrUndefined(tenant.logo) || tenant.logo === '') {
- const tenantLogo = await TenantStorage.getTenantLogo(tenant.id);
+ const tenantLogo = await TenantStorage.getTenantLogo(tenant);
tenant.logo = tenantLogo.logo;
}
sourceData.tenantLogoURL = tenant.logo;
@@ -919,7 +919,7 @@ export default class NotificationHandler {
if (tenant.id !== Constants.DEFAULT_TENANT) {
// Get the Tenant logo
if (Utils.isNullOrUndefined(tenant.logo) || tenant.logo === '') {
- const tenantLogo = await TenantStorage.getTenantLogo(tenant.id);
+ const tenantLogo = await TenantStorage.getTenantLogo(tenant);
tenant.logo = tenantLogo.logo;
}
sourceData.tenantLogoURL = tenant.logo;
@@ -961,7 +961,7 @@ export default class NotificationHandler {
if (tenant.id !== Constants.DEFAULT_TENANT) {
// Get the Tenant logo
if (Utils.isNullOrUndefined(tenant.logo) || tenant.logo === '') {
- const tenantLogo = await TenantStorage.getTenantLogo(tenant.id);
+ const tenantLogo = await TenantStorage.getTenantLogo(tenant);
tenant.logo = tenantLogo.logo;
}
sourceData.tenantLogoURL = tenant.logo;
@@ -1003,7 +1003,7 @@ export default class NotificationHandler {
if (tenant.id !== Constants.DEFAULT_TENANT) {
// Get the Tenant logo
if (Utils.isNullOrUndefined(tenant.logo) || tenant.logo === '') {
- const tenantLogo = await TenantStorage.getTenantLogo(tenant.id);
+ const tenantLogo = await TenantStorage.getTenantLogo(tenant);
tenant.logo = tenantLogo.logo;
}
sourceData.tenantLogoURL = tenant.logo;
@@ -1082,7 +1082,7 @@ export default class NotificationHandler {
if (tenant.id !== Constants.DEFAULT_TENANT) {
// Get the Tenant logo
if (Utils.isNullOrUndefined(tenant.logo) || tenant.logo === '') {
- const tenantLogo = await TenantStorage.getTenantLogo(tenant.id);
+ const tenantLogo = await TenantStorage.getTenantLogo(tenant);
tenant.logo = tenantLogo.logo;
}
sourceData.tenantLogoURL = tenant.logo;
@@ -1125,7 +1125,7 @@ export default class NotificationHandler {
if (tenant.id !== Constants.DEFAULT_TENANT) {
// Get the Tenant logo
if (Utils.isNullOrUndefined(tenant.logo) || tenant.logo === '') {
- const tenantLogo = await TenantStorage.getTenantLogo(tenant.id);
+ const tenantLogo = await TenantStorage.getTenantLogo(tenant);
tenant.logo = tenantLogo.logo;
}
sourceData.tenantLogoURL = tenant.logo;
@@ -1166,7 +1166,7 @@ export default class NotificationHandler {
if (tenant.id !== Constants.DEFAULT_TENANT) {
// Get the Tenant logo
if (Utils.isNullOrUndefined(tenant.logo) || tenant.logo === '') {
- const tenantLogo = await TenantStorage.getTenantLogo(tenant.id);
+ const tenantLogo = await TenantStorage.getTenantLogo(tenant);
tenant.logo = tenantLogo.logo;
}
sourceData.tenantLogoURL = tenant.logo;
@@ -1204,7 +1204,7 @@ export default class NotificationHandler {
if (tenant.id !== Constants.DEFAULT_TENANT) {
// Get the Tenant logo
if (Utils.isNullOrUndefined(tenant.logo) || tenant.logo === '') {
- const tenantLogo = await TenantStorage.getTenantLogo(tenant.id);
+ const tenantLogo = await TenantStorage.getTenantLogo(tenant);
tenant.logo = tenantLogo.logo;
}
sourceData.tenantLogoURL = tenant.logo;

MODIFY
src/server/rest/v1/service/TenantService.ts
src/server/rest/v1/service/TenantService.ts
@@ -25,6 +25,7 @@ import TenantValidator from '../validator/TenantValidator';
import UserStorage from '../../../../storage/mongodb/UserStorage';
import Utils from '../../../../utils/Utils';
import UtilsService from './UtilsService';
+import { filter } from 'lodash';
const MODULE_NAME = 'TenantService';
@@ -83,12 +84,15 @@ export default class TenantService {
let tenantLogo: TenantLogo;
// Get the logo using ID
if (filteredRequest.ID) {
- tenantLogo = await TenantStorage.getTenantLogo(filteredRequest.ID);
+ const tenant = await TenantStorage.getTenant(filteredRequest.ID);
+ if (tenant) {
+ tenantLogo = await TenantStorage.getTenantLogo(tenant);
+ }
// Get the logo using Subdomain
} else if (filteredRequest.Subdomain) {
const tenant = await TenantStorage.getTenantBySubdomain(filteredRequest.Subdomain, ['id']);
if (tenant) {
- tenantLogo = await TenantStorage.getTenantLogo(tenant.id);
+ tenantLogo = await TenantStorage.getTenantLogo(tenant);
}
}
if (tenantLogo?.logo) {

MODIFY
src/storage/mongodb/TenantStorage.ts
src/storage/mongodb/TenantStorage.ts
@@ -238,18 +238,18 @@ export default class TenantStorage {
await Logging.traceEnd(Constants.DEFAULT_TENANT, MODULE_NAME, 'deleteTenantDB', uniqueTimerID, { id });
}
- public static async getTenantLogo(tenantID: string): Promise<TenantLogo> {
+ public static async getTenantLogo(tenant: Tenant): Promise<TenantLogo> {
// Debug
- const uniqueTimerID = Logging.traceStart(tenantID, MODULE_NAME, 'getTenantLogo');
+ const uniqueTimerID = Logging.traceStart(tenant.id, MODULE_NAME, 'getTenantLogo');
// Check Tenant
- await DatabaseUtils.checkTenant(tenantID);
+ DatabaseUtils.checkTenantObject(tenant);
// Read DB
const tenantLogoMDB = await global.database.getCollection<{ _id: ObjectId; logo: string }>(Constants.DEFAULT_TENANT, 'tenantlogos')
- .findOne({ _id: DatabaseUtils.convertToObjectID(tenantID) });
+ .findOne({ _id: DatabaseUtils.convertToObjectID(tenant.id) });
// Debug
- await Logging.traceEnd(tenantID, MODULE_NAME, 'getTenantLogo', uniqueTimerID, tenantLogoMDB);
+ await Logging.traceEnd(tenant.id, MODULE_NAME, 'getTenantLogo', uniqueTimerID, tenantLogoMDB);
return {
- id: tenantID,
+ id: tenant.id,
logo: tenantLogoMDB ? tenantLogoMDB.logo : null
};
}

Change Tenant ID to Object TenantStorage