mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
feat: remove path alias.
feat: remove Webpack and depend on nodemon. feat: refactoring expenses. feat: optimize system users with caching. feat: architecture tenant optimize.
This commit is contained in:
27
server/src/api/middleware/TenantDependencyInjection.ts
Normal file
27
server/src/api/middleware/TenantDependencyInjection.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { Container } from 'typedi';
|
||||
import { ITenant } from 'interfaces';
|
||||
import { Request } from 'express';
|
||||
import TenancyService from 'services/Tenancy/TenancyService';
|
||||
import TenantsManagerService from 'services/Tenancy/TenantsManager';
|
||||
|
||||
export default (req: Request, tenant: ITenant) => {
|
||||
const { id: tenantId, organizationId } = tenant;
|
||||
const tenantServices = Container.get(TenancyService);
|
||||
const tenantsManager = Container.get(TenantsManagerService);
|
||||
|
||||
// Initialize the knex instance.
|
||||
tenantsManager.setupKnexInstance(tenant);
|
||||
|
||||
const knexInstance = tenantServices.knex(tenantId);
|
||||
const models = tenantServices.models(tenantId);
|
||||
const repositories = tenantServices.repositories(tenantId)
|
||||
const cacheInstance = tenantServices.cache(tenantId);
|
||||
|
||||
req.knex = knexInstance;
|
||||
req.organizationId = organizationId;
|
||||
req.tenant = tenant;
|
||||
req.tenantId = tenant.id;
|
||||
req.models = models;
|
||||
req.repositories = repositories;
|
||||
req.cache = cacheInstance;
|
||||
}
|
||||
Reference in New Issue
Block a user