Display logo in Tenant list + Additional fields
MODIFY
src/server/rest/service/TenantService.ts
src/server/rest/service/TenantService.ts
@@ -137,8 +137,12 @@ export default class TenantService {
const filteredRequest = TenantSecurity.filterTenantsRequest(req.query);
// Get the tenants
const tenants = await TenantStorage.getTenants(
- { search: filteredRequest.Search },
- { limit: filteredRequest.Limit, skip: filteredRequest.Skip, sort: filteredRequest.Sort });
+ {
+ search: filteredRequest.Search,
+ withLogo: filteredRequest.WithLogo,
+ },
+ { limit: filteredRequest.Limit, skip: filteredRequest.Skip, sort: filteredRequest.Sort },
+ [ 'id', 'name', 'email', 'subdomain', 'components', 'address', 'logo', 'createdOn', 'createdBy', 'lastChangedOn', 'lastChangedBy']);
// Filter
TenantSecurity.filterTenantsResponse(tenants, req.user);
// Return

MODIFY
src/server/rest/service/security/TenantSecurity.ts
src/server/rest/service/security/TenantSecurity.ts
@@ -19,6 +19,7 @@ export default class TenantSecurity {
public static filterTenantsRequest(request: any): HttpTenantsRequest {
const filteredRequest: HttpTenantsRequest = {} as HttpTenantsRequest;
filteredRequest.Search = sanitize(request.Search);
+ filteredRequest.WithLogo = UtilsSecurity.filterBoolean(request.WithLogo);
UtilsSecurity.filterSkipAndLimit(request, filteredRequest);
UtilsSecurity.filterSort(request, filteredRequest);
return filteredRequest;
@@ -39,7 +40,7 @@ export default class TenantSecurity {
filteredTenant.subdomain = tenant.subdomain;
filteredTenant.components = tenant.components;
filteredTenant.address = tenant.address;
-
+ filteredTenant.logo = tenant.logo;
// Created By / Last Changed By
UtilsSecurity.filterCreatedAndLastChanged(
filteredTenant, tenant, loggedUser);

MODIFY
src/storage/mongodb/CompanyStorage.ts
src/storage/mongodb/CompanyStorage.ts
@@ -164,6 +164,25 @@ export default class CompanyStorage {
}
// Remove the limit
aggregation.pop();
+ // Sort
+ if (!dbParams.sort) {
+ dbParams.sort = { name: 1 };
+ }
+ // Position coordinates
+ if (Utils.containsGPSCoordinates(params.locCoordinates)) {
+ dbParams.sort = { distanceMeters: 1 };
+ }
+ aggregation.push({
+ $sort: dbParams.sort
+ });
+ // Skip
+ if (dbParams.skip > 0) {
+ aggregation.push({ $skip: dbParams.skip });
+ }
+ // Limit
+ aggregation.push({
+ $limit: (dbParams.limit > 0 && dbParams.limit < Constants.DB_RECORD_COUNT_CEIL) ? dbParams.limit : Constants.DB_RECORD_COUNT_CEIL
+ });
// Site
if (params.withSites) {
DatabaseUtils.pushSiteLookupInAggregation(
@@ -184,25 +203,6 @@ export default class CompanyStorage {
DatabaseUtils.pushCreatedLastChangedInAggregation(tenantID, aggregation);
// Handle the ID
DatabaseUtils.pushRenameDatabaseID(aggregation);
- // Sort
- if (!dbParams.sort) {
- dbParams.sort = { name: 1 };
- }
- // Position coordinates
- if (Utils.containsGPSCoordinates(params.locCoordinates)) {
- dbParams.sort = { distanceMeters: 1 };
- }
- aggregation.push({
- $sort: dbParams.sort
- });
- // Skip
- if (dbParams.skip > 0) {
- aggregation.push({ $skip: dbParams.skip });
- }
- // Limit
- aggregation.push({
- $limit: (dbParams.limit > 0 && dbParams.limit < Constants.DB_RECORD_COUNT_CEIL) ? dbParams.limit : Constants.DB_RECORD_COUNT_CEIL
- });
// Project
DatabaseUtils.projectFields(aggregation, projectFields);
// Read DB

MODIFY
src/storage/mongodb/TenantStorage.ts
src/storage/mongodb/TenantStorage.ts
@@ -115,7 +115,7 @@ export default class TenantStorage {
// Delegate
public static async getTenants(
- params: { tenantIDs?: string[]; tenantName?: string; tenantSubdomain?: string; search?: string },
+ params: { tenantIDs?: string[]; tenantName?: string; tenantSubdomain?: string; search?: string, withLogo?: boolean },
dbParams: DbParams, projectFields?: string[]): Promise<DataResult<Tenant>> {
// Debug
const uniqueTimerID = Logging.traceStart(MODULE_NAME, 'getTenants');
@@ -190,6 +190,17 @@ export default class TenantStorage {
aggregation.push({
$limit: dbParams.limit
});
+ // Company Logo
+ if (params.withLogo) {
+ DatabaseUtils.pushCollectionLookupInAggregation('tenantlogos',
+ {
+ tenantID: null, aggregation, localField: '_id', foreignField: '_id',
+ asField: 'tenantlogos', oneToOneCardinality: true
+ }
+ );
+ // Rename
+ DatabaseUtils.pushRenameField(aggregation, 'tenantlogos.logo', 'logo');
+ }
// Handle the ID
DatabaseUtils.pushRenameDatabaseID(aggregation);
// Add Created By / Last Changed By

MODIFY
src/types/requests/HttpTenantRequest.ts
src/types/requests/HttpTenantRequest.ts
@@ -6,4 +6,5 @@ export interface HttpTenantVerifyRequest {
export interface HttpTenantsRequest extends HttpDatabaseRequest {
Search?: string;
+ WithLogo?: boolean;
}

Display logo in Tenant list + Additional fields