mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
add server to monorepo.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import { Container } from 'typedi';
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { injectI18nUtils } from './TenantDependencyInjection';
|
||||
|
||||
/**
|
||||
* I18n from organization settings.
|
||||
*/
|
||||
export default (req: Request, res: Response, next: NextFunction) => {
|
||||
const Logger = Container.get('logger');
|
||||
const I18n = Container.get('i18n');
|
||||
|
||||
const { tenantId, tenant } = req;
|
||||
|
||||
if (!req.user) {
|
||||
throw new Error('Should load this middleware after `JWTAuth`.');
|
||||
}
|
||||
if (!req.settings) {
|
||||
throw new Error('Should load this middleware after `SettingsMiddleware`.');
|
||||
}
|
||||
// Get the organization language from settings.
|
||||
const { language } = tenant.metadata;
|
||||
|
||||
if (language) {
|
||||
I18n.setLocale(req, language);
|
||||
}
|
||||
Logger.info('[i18n_authenticated_middleware] set locale language to i18n.', {
|
||||
language,
|
||||
user: req.user,
|
||||
});
|
||||
const tenantServices = Container.get(HasTenancyService);
|
||||
const tenantContainer = tenantServices.tenantContainer(tenantId);
|
||||
|
||||
tenantContainer.set('i18n', injectI18nUtils(req));
|
||||
|
||||
next();
|
||||
};
|
||||
Reference in New Issue
Block a user