refactor: items services to Nestjs

This commit is contained in:
Ahmed Bouhuolia
2024-12-15 13:04:41 +02:00
parent 70211980aa
commit 0a112c5655
20 changed files with 897 additions and 18 deletions

View File

@@ -17,13 +17,22 @@ export class TenancyContext {
/**
* Get the current tenant.
* @param {boolean} withMetadata - If true, the tenant metadata will be fetched.
* @returns
*/
getTenant() {
getTenant(withMetadata: boolean = false) {
// Get the tenant from the request headers.
const organizationId = this.cls.get('organizationId');
return this.systemTenantModel.query().findOne({ organizationId });
if (!organizationId) {
throw new Error('Tenant not found');
}
const query = this.systemTenantModel.query().findOne({ organizationId });
if (withMetadata) {
query.withGraphFetched('metadata');
}
return query;
}
/**

View File

@@ -1,10 +1,14 @@
import { Knex } from 'knex';
import { Global, Module, Scope } from '@nestjs/common';
import { TENANCY_DB_CONNECTION } from '../TenancyDB/TenancyDB.constants';
import { Item } from '../../../modules/Items/models/Item';
import { Account } from '@/modules/Accounts/models/Account';
import { TenantModel } from '@/modules/System/models/TenantModel';
import { TenantMetadata } from '@/modules/System/models/TenantMetadataModel';
const models = [Item, Account, TenantModel, TenantMetadata];
const models = [Item, Account];
const modelProviders = models.map((model) => {
return {
provide: model.name,