Handle consistency is returning images in all service classes
MODIFY
src/integration/billing/stripe/StripeBillingIntegration.ts
src/integration/billing/stripe/StripeBillingIntegration.ts
@@ -23,7 +23,7 @@ import ICustomerListOptions = Stripe.customers.ICustomerListOptions;
import ItaxRateSearchOptions = Stripe.taxRates.ItaxRateSearchOptions;
import IInvoice = Stripe.invoices.IInvoice;
-const MODULE_NAME = 'StripeBilling';
+const MODULE_NAME = 'StripeBillingIntegration';
export default class StripeBillingIntegration extends BillingIntegration<StripeBillingSetting> {
private static readonly STRIPE_MAX_LIST = 100;

MODIFY
src/server/rest/service/CompanyService.ts
src/server/rest/service/CompanyService.ts
@@ -31,10 +31,8 @@ export default class CompanyService {
throw new AppAuthError({
errorCode: HTTPAuthError.ERROR,
user: req.user,
- action: Action.DELETE,
- entity: Entity.COMPANY,
- module: MODULE_NAME,
- method: 'handleDeleteCompany',
+ action: Action.DELETE, entity: Entity.COMPANY,
+ module: MODULE_NAME, method: 'handleDeleteCompany',
value: companyID
});
}
@@ -71,10 +69,8 @@ export default class CompanyService {
throw new AppAuthError({
errorCode: HTTPAuthError.ERROR,
user: req.user,
- action: Action.READ,
- entity: Entity.COMPANY,
- module: MODULE_NAME,
- method: 'handleGetCompany',
+ action: Action.READ, entity: Entity.COMPANY,
+ module: MODULE_NAME, method: 'handleGetCompany',
value: filteredRequest.ID
});
}
@@ -96,27 +92,25 @@ export default class CompanyService {
Action.READ, Entity.COMPANY, MODULE_NAME, 'handleGetCompanyLogo');
// Filter
const companyID = CompanySecurity.filterCompanyRequestByID(req.query);
- // Charge Box is mandatory
UtilsService.assertIdIsProvided(action, companyID, MODULE_NAME, 'handleGetCompanyLogo', req.user);
// Check auth
if (!Authorizations.canReadCompany(req.user, companyID)) {
throw new AppAuthError({
errorCode: HTTPAuthError.ERROR,
user: req.user,
- action: Action.READ,
- entity: Entity.COMPANY,
- module: MODULE_NAME,
- method: 'handleGetCompanyLogo',
+ action: Action.READ, entity: Entity.COMPANY,
+ module: MODULE_NAME, method: 'handleGetCompanyLogo',
value: companyID
});
}
- // Get it
- const companyLogo = await CompanyStorage.getCompanyLogo(req.user.tenantID, companyID);
- // Check
- UtilsService.assertObjectExists(action, companyLogo, `Company with ID '${companyID}' does not exist`,
+ // Get Company
+ const company = await CompanyStorage.getCompany(req.user.tenantID, companyID);
+ UtilsService.assertObjectExists(action, company, `Company with ID '${companyID}' does not exist`,
MODULE_NAME, 'handleGetCompanyLogo', req.user);
+ // Get the Logo
+ const companyLogo = await CompanyStorage.getCompanyLogo(req.user.tenantID, companyID);
// Return
- res.json({ id: companyLogo.id, logo: companyLogo.logo });
+ res.json(companyLogo);
next();
}
@@ -129,10 +123,8 @@ export default class CompanyService {
throw new AppAuthError({
errorCode: HTTPAuthError.ERROR,
user: req.user,
- action: Action.LIST,
- entity: Entity.COMPANIES,
- module: MODULE_NAME,
- method: 'handleGetCompanies'
+ action: Action.LIST, entity: Entity.COMPANIES,
+ module: MODULE_NAME, method: 'handleGetCompanies'
});
}
// Filter
@@ -167,10 +159,8 @@ export default class CompanyService {
throw new AppAuthError({
errorCode: HTTPAuthError.ERROR,
user: req.user,
- action: Action.CREATE,
- entity: Entity.COMPANY,
- module: MODULE_NAME,
- method: 'handleCreateCompany'
+ action: Action.CREATE, entity: Entity.COMPANY,
+ module: MODULE_NAME, method: 'handleCreateCompany'
});
}
// Filter
@@ -210,17 +200,14 @@ export default class CompanyService {
throw new AppAuthError({
errorCode: HTTPAuthError.ERROR,
user: req.user,
- action: Action.UPDATE,
- entity: Entity.COMPANY,
- module: MODULE_NAME,
- method: 'handleUpdateCompany',
+ action: Action.UPDATE, entity: Entity.COMPANY,
+ module: MODULE_NAME, method: 'handleUpdateCompany',
value: filteredRequest.id
});
}
- // Check email
+ // Get Company
const company = await CompanyStorage.getCompany(req.user.tenantID, filteredRequest.id);
- // Check
- UtilsService.assertObjectExists(action, company, `Site Area with ID '${filteredRequest.id}' does not exist`,
+ UtilsService.assertObjectExists(action, company, `Company with ID '${filteredRequest.id}' does not exist`,
MODULE_NAME, 'handleUpdateCompany', req.user);
// Check Mandatory fields
Utils.checkIfCompanyValid(filteredRequest, req);

MODIFY
src/server/rest/service/SiteAreaService.ts
src/server/rest/service/SiteAreaService.ts
@@ -254,14 +254,9 @@ export default class SiteAreaService {
Action.READ, Entity.SITE_AREA, MODULE_NAME, 'handleGetSiteAreaImage');
// Filter
const siteAreaID = SiteAreaSecurity.filterSiteAreaRequestByID(req.query);
- // Charge Box is mandatory
UtilsService.assertIdIsProvided(action, siteAreaID, MODULE_NAME, 'handleGetSiteAreaImage', req.user);
- // Get it
- const siteArea = await SiteAreaStorage.getSiteArea(req.user.tenantID, siteAreaID);
- UtilsService.assertObjectExists(action, siteArea, `Site Area with ID '${siteAreaID}' does not exist`,
- MODULE_NAME, 'handleGetSiteAreaImage', req.user);
// Check auth
- if (!Authorizations.canReadSiteArea(req.user, siteArea.siteID)) {
+ if (!Authorizations.canReadSiteArea(req.user, siteAreaID)) {
throw new AppAuthError({
errorCode: HTTPAuthError.ERROR,
user: req.user,
@@ -271,11 +266,13 @@ export default class SiteAreaService {
});
}
// Get it
- const siteAreaImage = await SiteAreaStorage.getSiteAreaImage(req.user.tenantID, siteAreaID);
- UtilsService.assertObjectExists(action, siteAreaImage, `Site Area Image with ID '${siteAreaID}' does not exist`,
+ const siteArea = await SiteAreaStorage.getSiteArea(req.user.tenantID, siteAreaID);
+ UtilsService.assertObjectExists(action, siteArea, `Site Area with ID '${siteAreaID}' does not exist`,
MODULE_NAME, 'handleGetSiteAreaImage', req.user);
+ // Get it
+ const siteAreaImage = await SiteAreaStorage.getSiteAreaImage(req.user.tenantID, siteAreaID);
// Return
- res.json({ id: siteAreaImage.id, image: siteAreaImage.image });
+ res.json(siteAreaImage);
next();
}

MODIFY
src/server/rest/service/TenantService.ts
src/server/rest/service/TenantService.ts
@@ -35,10 +35,8 @@ export default class TenantService {
throw new AppAuthError({
errorCode: HTTPAuthError.ERROR,
user: req.user,
- action: Action.DELETE,
- entity: Entity.TENANT,
- module: MODULE_NAME,
- method: 'handleDeleteTenant',
+ action: Action.DELETE, entity: Entity.TENANT,
+ module: MODULE_NAME, method: 'handleDeleteTenant',
value: id
});
}
@@ -52,8 +50,7 @@ export default class TenantService {
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.OBJECT_DOES_NOT_EXIST_ERROR,
message: `Your own tenant with id '${tenant.id}' cannot be deleted`,
- module: MODULE_NAME,
- method: 'handleDeleteTenant',
+ module: MODULE_NAME, method: 'handleDeleteTenant',
user: req.user,
action: action
});
@@ -79,13 +76,24 @@ export default class TenantService {
// Filter
const tenantID = TenantSecurity.filterTenantRequestByID(req.query);
UtilsService.assertIdIsProvided(action, tenantID, MODULE_NAME, 'handleGetTenantLogo', req.user);
- // Get it
- const tenantLogo = await TenantStorage.getTenantLogo(tenantID);
- // Check
- UtilsService.assertObjectExists(action, tenantLogo, `Tenant with ID '${tenantID}' does not exist`,
+ // Check auth
+ if (!Authorizations.canReadTenant(req.user)) {
+ throw new AppAuthError({
+ errorCode: HTTPAuthError.ERROR,
+ user: req.user,
+ action: Action.READ, entity: Entity.TENANT,
+ module: MODULE_NAME, method: 'handleGetTenantLogo',
+ value: tenantID
+ });
+ }
+ // Get Tenant
+ const tenant = await TenantStorage.getTenant(tenantID);
+ UtilsService.assertObjectExists(action, tenant, `Tenant with ID '${tenantID}' does not exist`,
MODULE_NAME, 'handleGetTenantLogo', req.user);
+ // Get Logo
+ const tenantLogo = await TenantStorage.getTenantLogo(tenantID);
// Return
- res.json({ id: tenantLogo.id, logo: tenantLogo.logo });
+ res.json(tenantLogo);
next();
}
@@ -98,10 +106,8 @@ export default class TenantService {
throw new AppAuthError({
errorCode: HTTPAuthError.ERROR,
user: req.user,
- action: Action.READ,
- entity: Entity.TENANT,
- module: MODULE_NAME,
- method: 'handleGetTenant',
+ action: Action.READ, entity: Entity.TENANT,
+ module: MODULE_NAME, method: 'handleGetTenant',
value: tenantID
});
}
@@ -112,8 +118,7 @@ export default class TenantService {
// Return
res.json(
// Filter
- TenantSecurity.filterTenantResponse(
- tenant, req.user)
+ TenantSecurity.filterTenantResponse(tenant, req.user)
);
next();
}
@@ -124,10 +129,8 @@ export default class TenantService {
throw new AppAuthError({
errorCode: HTTPAuthError.ERROR,
user: req.user,
- action: Action.LIST,
- entity: Entity.TENANTS,
- module: MODULE_NAME,
- method: 'handleGetTenants'
+ action: Action.LIST, entity: Entity.TENANTS,
+ module: MODULE_NAME, method: 'handleGetTenants'
});
}
// Filter
@@ -151,10 +154,8 @@ export default class TenantService {
throw new AppAuthError({
errorCode: HTTPAuthError.ERROR,
user: req.user,
- action: Action.CREATE,
- entity: Entity.TENANT,
- module: MODULE_NAME,
- method: 'handleCreateTenant'
+ action: Action.CREATE, entity: Entity.TENANT,
+ module: MODULE_NAME, method: 'handleCreateTenant'
});
}
// Check the Tenant's name
@@ -164,8 +165,7 @@ export default class TenantService {
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.USER_EMAIL_ALREADY_EXIST_ERROR,
message: `The tenant with name '${filteredRequest.name}' already exists`,
- module: MODULE_NAME,
- method: 'handleCreateTenant',
+ module: MODULE_NAME, method: 'handleCreateTenant',
user: req.user,
action: action
});
@@ -177,8 +177,7 @@ export default class TenantService {
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.USER_EMAIL_ALREADY_EXIST_ERROR,
message: `The tenant with subdomain '${filteredRequest.subdomain}' already exists`,
- module: MODULE_NAME,
- method: 'handleCreateTenant',
+ module: MODULE_NAME, method: 'handleCreateTenant',
user: req.user,
action: action
});
@@ -246,10 +245,8 @@ export default class TenantService {
throw new AppAuthError({
errorCode: HTTPAuthError.ERROR,
user: req.user,
- action: Action.UPDATE,
- entity: Entity.TENANT,
- module: MODULE_NAME,
- method: 'handleUpdateTenant',
+ action: Action.UPDATE, entity: Entity.TENANT,
+ module: MODULE_NAME, method: 'handleUpdateTenant',
value: tenantUpdate.id
});
}
@@ -274,7 +271,6 @@ export default class TenantService {
});
}
}
-
// Update timestamp
tenantUpdate.lastChangedBy = { 'id': req.user.id };
tenantUpdate.lastChangedOn = new Date();

MODIFY
src/server/rest/service/UserService.ts
src/server/rest/service/UserService.ts
@@ -648,45 +648,35 @@ export default class UserService {
public static async handleGetUserImage(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const filteredRequest = { ID: UserSecurity.filterUserByIDRequest(req.query) };
- // User mandatory
- if (!filteredRequest.ID) {
- throw new AppError({
- source: Constants.CENTRAL_SERVER,
- errorCode: HTTPError.GENERAL_ERROR,
- message: 'User\'s ID must be provided',
- module: MODULE_NAME, method: 'handleGetUserImage',
- user: req.user,
- action: action
- });
- }
+ const userID = UserSecurity.filterUserByIDRequest(req.query);
+ UtilsService.assertIdIsProvided(action, userID, MODULE_NAME, 'handleGetUserImage', req.user);
// Check auth
- if (!Authorizations.canReadUser(req.user, filteredRequest.ID)) {
+ if (!Authorizations.canReadUser(req.user, userID)) {
throw new AppAuthError({
errorCode: HTTPAuthError.ERROR,
user: req.user,
action: Action.READ, entity: Entity.USER,
module: MODULE_NAME, method: 'handleGetUserImage',
- value: filteredRequest.ID
+ value: userID
});
}
// Get the logged user
- const user = await UserStorage.getUser(req.user.tenantID, filteredRequest.ID);
- UtilsService.assertObjectExists(action, user, `User '${filteredRequest.ID}' does not exist`,
+ const user = await UserStorage.getUser(req.user.tenantID, userID);
+ UtilsService.assertObjectExists(action, user, `User '${userID}' does not exist`,
MODULE_NAME, 'handleGetUserImage', req.user);
// Deleted?
if (user.deleted) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.OBJECT_DOES_NOT_EXIST_ERROR,
- message: `User with ID '${filteredRequest.ID}' is logically deleted`,
+ message: `User with ID '${userID}' is logically deleted`,
module: MODULE_NAME, method: 'handleGetUserImage',
user: req.user,
action: action
});
}
// Get the user image
- const userImage = await UserStorage.getUserImage(req.user.tenantID, filteredRequest.ID);
+ const userImage = await UserStorage.getUserImage(req.user.tenantID, userID);
// Ok
res.json(userImage);
next();

Handle consistency is returning images in all service classes