add server to monorepo.

This commit is contained in:
a.bouhuolia
2023-02-03 11:57:50 +02:00
parent 28e309981b
commit 80b97b5fdc
1303 changed files with 137049 additions and 0 deletions

View File

@@ -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();
};