Modifying code to use req.tenant
MODIFY
src/server/rest/v1/service/BillingService.ts
src/server/rest/v1/service/BillingService.ts
@@ -278,10 +278,8 @@ export default class BillingService {
}
// Filter
const filteredRequest = BillingSecurity.filterGetInvoicesRequest(req.query);
- // Fetch tenant for tenant id
- const tenant = await TenantStorage.getTenant(req.user.tenantID);
// Get invoices
- const invoices = await BillingStorage.getInvoices(tenant,
+ const invoices = await BillingStorage.getInvoices(req.tenant,
{
userIDs: !Authorizations.isAdmin(req.user) ? [req.user.id] : (filteredRequest.UserID ? filteredRequest.UserID.split('|') : null),
invoiceStatus: filteredRequest.Status ? filteredRequest.Status.split('|') as BillingInvoiceStatus[] : null,
@@ -316,10 +314,8 @@ export default class BillingService {
if ((await Authorizations.canListUsers(req.user)).authorized) {
userProject = [ 'userID', 'user.id', 'user.name', 'user.firstName', 'user.email' ];
}
- // Fetch tenant based on Tenant ID
- const tenant = await TenantStorage.getTenant(req.user.tenantID);
// Get invoice
- const invoice = await BillingStorage.getInvoice(tenant, filteredRequest.ID,
+ const invoice = await BillingStorage.getInvoice(req.tenant, filteredRequest.ID,
[
'id', 'number', 'status', 'amount', 'createdOn', 'currency', 'downloadable', 'sessions',
...userProject
@@ -648,10 +644,8 @@ export default class BillingService {
Action.DOWNLOAD, Entity.BILLING, MODULE_NAME, 'handleDownloadInvoice');
// Filter
const filteredRequest = BillingSecurity.filterDownloadInvoiceRequest(req.query);
- // Fetch tenant based on tenant ID
- const tenant = await TenantStorage.getTenant(req.user.tenantID);
// Get the Invoice
- const billingInvoice = await BillingStorage.getInvoice(tenant, filteredRequest.ID);
+ const billingInvoice = await BillingStorage.getInvoice(req.tenant, filteredRequest.ID);
UtilsService.assertObjectExists(action, billingInvoice, `Invoice ID '${filteredRequest.ID}' does not exist`,
MODULE_NAME, 'handleDownloadInvoice', req.user);
// Check Auth

Modifying code to use req.tenant