mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 06:10:31 +00:00
feat: wip migrate server to nestjs
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { ClsService } from 'nestjs-cls';
|
||||
import { SystemUser } from '../System/models/SystemUser';
|
||||
import { TenantModel } from '../System/models/TenantModel';
|
||||
|
||||
@Injectable()
|
||||
export class TenancyContext {
|
||||
constructor(
|
||||
private readonly cls: ClsService,
|
||||
|
||||
@Inject(SystemUser.name)
|
||||
private readonly systemUserModel: typeof SystemUser,
|
||||
|
||||
@Inject(TenantModel.name)
|
||||
private readonly systemTenantModel: typeof TenantModel,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Get the current tenant.
|
||||
* @returns
|
||||
*/
|
||||
getTenant() {
|
||||
// Get the tenant from the request headers.
|
||||
const organizationId = this.cls.get('organizationId');
|
||||
|
||||
return this.systemTenantModel.query().findOne({ organizationId });
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns
|
||||
*/
|
||||
getSystemUser() {
|
||||
// Get the user from the request headers.
|
||||
const userId = this.cls.get('userId');
|
||||
|
||||
return this.systemUserModel.query().findOne({ id: userId });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user