Files
bigcapital/server/src/api/middleware/TenantDependencyInjection.ts
Ahmed Bouhuolia 99e6fe273f refactoring: custom views service.
fix: constraints of delete item from storage.
fix: constraints of delete item category from storage.
fix: localize database seeds files.
fix: view meta data in accounts list response.
2020-10-05 19:09:56 +02:00

29 lines
1.0 KiB
TypeScript

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);
tenantServices.setI18nLocals(tenantId, { __: req.__ });
req.knex = knexInstance;
req.organizationId = organizationId;
req.tenant = tenant;
req.tenantId = tenant.id;
req.models = models;
req.repositories = repositories;
req.cache = cacheInstance;
}