mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 22:30:31 +00:00
refactor
This commit is contained in:
@@ -7,8 +7,6 @@ import { importWebpackSeedModule } from './Utils';
|
|||||||
import { DEFAULT_LOAD_EXTENSIONS } from './constants';
|
import { DEFAULT_LOAD_EXTENSIONS } from './constants';
|
||||||
import { filterMigrations } from './MigrateUtils';
|
import { filterMigrations } from './MigrateUtils';
|
||||||
|
|
||||||
const readdir = promisify(fs.readdir);
|
|
||||||
|
|
||||||
class FsMigrations {
|
class FsMigrations {
|
||||||
private sortDirsSeparately: boolean;
|
private sortDirsSeparately: boolean;
|
||||||
private migrationsPaths: string[];
|
private migrationsPaths: string[];
|
||||||
@@ -23,7 +21,7 @@ class FsMigrations {
|
|||||||
constructor(
|
constructor(
|
||||||
migrationDirectories: string[],
|
migrationDirectories: string[],
|
||||||
sortDirsSeparately: boolean,
|
sortDirsSeparately: boolean,
|
||||||
loadExtensions: string[]
|
loadExtensions: string[],
|
||||||
) {
|
) {
|
||||||
this.sortDirsSeparately = sortDirsSeparately;
|
this.sortDirsSeparately = sortDirsSeparately;
|
||||||
|
|
||||||
@@ -42,6 +40,8 @@ class FsMigrations {
|
|||||||
// Get a list of files in all specified migration directories
|
// Get a list of files in all specified migration directories
|
||||||
const readMigrationsPromises = this.migrationsPaths.map((configDir) => {
|
const readMigrationsPromises = this.migrationsPaths.map((configDir) => {
|
||||||
const absoluteDir = path.resolve(process.cwd(), configDir);
|
const absoluteDir = path.resolve(process.cwd(), configDir);
|
||||||
|
const readdir = promisify(fs.readdir);
|
||||||
|
|
||||||
return readdir(absoluteDir).then((files) => ({
|
return readdir(absoluteDir).then((files) => ({
|
||||||
files,
|
files,
|
||||||
configDir,
|
configDir,
|
||||||
@@ -56,7 +56,7 @@ class FsMigrations {
|
|||||||
migrationDirectory.files = migrationDirectory.files.sort();
|
migrationDirectory.files = migrationDirectory.files.sort();
|
||||||
}
|
}
|
||||||
migrationDirectory.files.forEach((file) =>
|
migrationDirectory.files.forEach((file) =>
|
||||||
acc.push({ file, directory: migrationDirectory.configDir })
|
acc.push({ file, directory: migrationDirectory.configDir }),
|
||||||
);
|
);
|
||||||
return acc;
|
return acc;
|
||||||
}, []);
|
}, []);
|
||||||
@@ -67,13 +67,13 @@ class FsMigrations {
|
|||||||
return filterMigrations(
|
return filterMigrations(
|
||||||
this,
|
this,
|
||||||
migrations,
|
migrations,
|
||||||
loadExtensions || this.loadExtensions
|
loadExtensions || this.loadExtensions,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return filterMigrations(
|
return filterMigrations(
|
||||||
this,
|
this,
|
||||||
sortBy(migrations, 'file'),
|
sortBy(migrations, 'file'),
|
||||||
loadExtensions || this.loadExtensions
|
loadExtensions || this.loadExtensions,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Seeder } from "./Seeder";
|
// @ts-nocheck
|
||||||
|
import { Seeder } from './Seeder';
|
||||||
|
|
||||||
export class TenantSeeder extends Seeder {
|
export class TenantSeeder extends Seeder {
|
||||||
public knex: any;
|
public knex: any;
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
|
||||||
const { promisify } = require('util');
|
|
||||||
const readFile = promisify(fs.readFile);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detarmines the module type of the given file path.
|
* Detarmines the module type of the given file path.
|
||||||
* @param {string} filepath
|
* @param {string} filepath
|
||||||
@@ -11,6 +8,8 @@ const readFile = promisify(fs.readFile);
|
|||||||
*/
|
*/
|
||||||
async function isModuleType(filepath: string): boolean {
|
async function isModuleType(filepath: string): boolean {
|
||||||
if (process.env.npm_package_json) {
|
if (process.env.npm_package_json) {
|
||||||
|
const { promisify } = require('util');
|
||||||
|
const readFile = promisify(fs.readFile);
|
||||||
// npm >= 7.0.0
|
// npm >= 7.0.0
|
||||||
const packageJson = JSON.parse(
|
const packageJson = JSON.parse(
|
||||||
await readFile(process.env.npm_package_json, 'utf-8'),
|
await readFile(process.env.npm_package_json, 'utf-8'),
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ export class Exportable {
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
public async exportable(
|
public async exportable(
|
||||||
tenantId: number,
|
query: Record<string, any>,
|
||||||
query: Record<string, any>
|
|
||||||
): Promise<Array<Record<string, any>>> {
|
): Promise<Array<Record<string, any>>> {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,16 +7,27 @@ import { BullModule } from '@nestjs/bullmq';
|
|||||||
import { OrganizationBuildQueue } from './Organization.types';
|
import { OrganizationBuildQueue } from './Organization.types';
|
||||||
import { OrganizationBuildProcessor } from './processors/OrganizationBuild.processor';
|
import { OrganizationBuildProcessor } from './processors/OrganizationBuild.processor';
|
||||||
import { CommandOrganizationValidators } from './commands/CommandOrganizationValidators.service';
|
import { CommandOrganizationValidators } from './commands/CommandOrganizationValidators.service';
|
||||||
|
import { TenancyContext } from '../Tenancy/TenancyContext.service';
|
||||||
|
import { TenantDBManagerModule } from '../TenantDBManager/TenantDBManager.module';
|
||||||
|
import { TenantsManagerService } from '../TenantDBManager/TenantsManager';
|
||||||
|
import { OrganizationBaseCurrencyLocking } from './Organization/OrganizationBaseCurrencyLocking.service';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
providers: [
|
providers: [
|
||||||
|
TenancyContext,
|
||||||
GetCurrentOrganizationService,
|
GetCurrentOrganizationService,
|
||||||
BuildOrganizationService,
|
BuildOrganizationService,
|
||||||
UpdateOrganizationService,
|
UpdateOrganizationService,
|
||||||
OrganizationBuildProcessor,
|
OrganizationBuildProcessor,
|
||||||
CommandOrganizationValidators,
|
CommandOrganizationValidators,
|
||||||
|
OrganizationBaseCurrencyLocking,
|
||||||
|
],
|
||||||
|
imports: [
|
||||||
|
BullModule.registerQueue({
|
||||||
|
name: OrganizationBuildQueue,
|
||||||
|
}),
|
||||||
|
TenantDBManagerModule,
|
||||||
],
|
],
|
||||||
imports: [BullModule.registerQueue({ name: OrganizationBuildQueue })],
|
|
||||||
controllers: [OrganizationController],
|
controllers: [OrganizationController],
|
||||||
})
|
})
|
||||||
export class OrganizationModule {}
|
export class OrganizationModule {}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
// @ts-nocheck
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { isEmpty } from 'lodash';
|
import { isEmpty } from 'lodash';
|
||||||
|
|
||||||
|
|
||||||
interface MutateBaseCurrencyLockMeta {
|
interface MutateBaseCurrencyLockMeta {
|
||||||
modelName: string;
|
modelName: string;
|
||||||
pluralName?: string;
|
pluralName?: string;
|
||||||
@@ -16,7 +16,7 @@ export class OrganizationBaseCurrencyLocking {
|
|||||||
const Models = this.tenancy.models(tenantId);
|
const Models = this.tenancy.models(tenantId);
|
||||||
|
|
||||||
const filteredEntries = Object.entries(Models).filter(
|
const filteredEntries = Object.entries(Models).filter(
|
||||||
([key, Model]) => !!Model.preventMutateBaseCurrency
|
([key, Model]) => !!Model.preventMutateBaseCurrency,
|
||||||
);
|
);
|
||||||
return Object.fromEntries(filteredEntries);
|
return Object.fromEntries(filteredEntries);
|
||||||
};
|
};
|
||||||
@@ -27,7 +27,7 @@ export class OrganizationBaseCurrencyLocking {
|
|||||||
* @returns {Promise<MutateBaseCurrencyLockMeta | false>}
|
* @returns {Promise<MutateBaseCurrencyLockMeta | false>}
|
||||||
*/
|
*/
|
||||||
private isModelMutateLocked = async (
|
private isModelMutateLocked = async (
|
||||||
Model
|
Model,
|
||||||
): Promise<MutateBaseCurrencyLockMeta | false> => {
|
): Promise<MutateBaseCurrencyLockMeta | false> => {
|
||||||
const validateQuery = Model.query();
|
const validateQuery = Model.query();
|
||||||
|
|
||||||
@@ -53,17 +53,17 @@ export class OrganizationBaseCurrencyLocking {
|
|||||||
* @returns {Promise<MutateBaseCurrencyLockMeta[]>}
|
* @returns {Promise<MutateBaseCurrencyLockMeta[]>}
|
||||||
*/
|
*/
|
||||||
public async baseCurrencyMutateLocks(
|
public async baseCurrencyMutateLocks(
|
||||||
tenantId: number
|
tenantId: number,
|
||||||
): Promise<MutateBaseCurrencyLockMeta[]> {
|
): Promise<MutateBaseCurrencyLockMeta[]> {
|
||||||
const PreventedModels = this.getModelsPreventsMutate(tenantId);
|
const PreventedModels = this.getModelsPreventsMutate(tenantId);
|
||||||
|
|
||||||
const opers = Object.entries(PreventedModels).map(([ModelName, Model]) =>
|
const opers = Object.entries(PreventedModels).map(([ModelName, Model]) =>
|
||||||
this.isModelMutateLocked(Model)
|
this.isModelMutateLocked(Model),
|
||||||
);
|
);
|
||||||
const results = await Promise.all(opers);
|
const results = await Promise.all(opers);
|
||||||
|
|
||||||
return results.filter(
|
return results.filter(
|
||||||
(result) => result !== false
|
(result) => result !== false,
|
||||||
) as MutateBaseCurrencyLockMeta[];
|
) as MutateBaseCurrencyLockMeta[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import moment from 'moment-timezone';
|
import * as momentTz from 'moment-timezone';
|
||||||
import {
|
import {
|
||||||
IsHexColor,
|
IsHexColor,
|
||||||
IsIn,
|
IsIn,
|
||||||
@@ -41,7 +41,7 @@ export class BuildOrganizationDto {
|
|||||||
})
|
})
|
||||||
baseCurrency: string;
|
baseCurrency: string;
|
||||||
|
|
||||||
@IsIn(moment.tz.names())
|
@IsIn(momentTz.tz.names())
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
description: 'Timezone of the organization',
|
description: 'Timezone of the organization',
|
||||||
example: 'America/New_York',
|
example: 'America/New_York',
|
||||||
@@ -105,7 +105,7 @@ export class UpdateOrganizationDto {
|
|||||||
baseCurrency?: string;
|
baseCurrency?: string;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsIn(moment.tz.names())
|
@IsIn(momentTz.tz.names())
|
||||||
@ApiPropertyOptional({
|
@ApiPropertyOptional({
|
||||||
description: 'Timezone of the organization',
|
description: 'Timezone of the organization',
|
||||||
example: 'America/New_York',
|
example: 'America/New_York',
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import { TenancyContext } from '../Tenancy/TenancyContext.service';
|
|||||||
import { NewSubscriptionService } from './commands/NewSubscription.service';
|
import { NewSubscriptionService } from './commands/NewSubscription.service';
|
||||||
import { GetSubscriptionsService } from './queries/GetSubscriptions.service';
|
import { GetSubscriptionsService } from './queries/GetSubscriptions.service';
|
||||||
import { GetLemonSqueezyCheckoutService } from './queries/GetLemonSqueezyCheckout.service';
|
import { GetLemonSqueezyCheckoutService } from './queries/GetLemonSqueezyCheckout.service';
|
||||||
|
import { PlanSubscriptionRepository } from './repositories/PlanSubscription.repository';
|
||||||
|
|
||||||
const models = [InjectSystemModel(Plan), InjectSystemModel(PlanSubscription)];
|
const models = [InjectSystemModel(Plan), InjectSystemModel(PlanSubscription)];
|
||||||
|
|
||||||
@@ -27,6 +28,7 @@ const models = [InjectSystemModel(Plan), InjectSystemModel(PlanSubscription)];
|
|||||||
providers: [
|
providers: [
|
||||||
...models,
|
...models,
|
||||||
TenancyContext,
|
TenancyContext,
|
||||||
|
PlanSubscriptionRepository,
|
||||||
NewSubscriptionService,
|
NewSubscriptionService,
|
||||||
GetSubscriptionsService,
|
GetSubscriptionsService,
|
||||||
CancelLemonSubscription,
|
CancelLemonSubscription,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { SystemKnexConnection } from '../SystemDB/SystemDB.constants';
|
|||||||
import { SystemModelsConnection } from './SystemModels.constants';
|
import { SystemModelsConnection } from './SystemModels.constants';
|
||||||
import { SystemUser } from '../models/SystemUser';
|
import { SystemUser } from '../models/SystemUser';
|
||||||
import { TenantMetadata } from '../models/TenantMetadataModel';
|
import { TenantMetadata } from '../models/TenantMetadataModel';
|
||||||
|
import { TenantRepository } from '../repositories/Tenant.repository';
|
||||||
|
|
||||||
const models = [SystemUser, PlanSubscription, TenantModel, TenantMetadata];
|
const models = [SystemUser, PlanSubscription, TenantModel, TenantMetadata];
|
||||||
|
|
||||||
@@ -35,7 +36,7 @@ const providers = [
|
|||||||
|
|
||||||
@Global()
|
@Global()
|
||||||
@Module({
|
@Module({
|
||||||
providers: [...providers],
|
providers: [...providers, TenantRepository],
|
||||||
exports: [...providers],
|
exports: [...providers, TenantRepository],
|
||||||
})
|
})
|
||||||
export class SystemModelsModule {}
|
export class SystemModelsModule {}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Knex } from 'knex';
|
import { Knex } from 'knex';
|
||||||
import { Inject, Injectable } from '@nestjs/common';
|
import { Global, Inject, Injectable } from '@nestjs/common';
|
||||||
import uniqid from 'uniqid';
|
import uniqid from 'uniqid';
|
||||||
import { TenantRepository as TenantBaseRepository } from '@/common/repository/TenantRepository';
|
import { TenantRepository as TenantBaseRepository } from '@/common/repository/TenantRepository';
|
||||||
import { SystemKnexConnection } from '../SystemDB/SystemDB.constants';
|
import { SystemKnexConnection } from '../SystemDB/SystemDB.constants';
|
||||||
@@ -10,13 +10,13 @@ import { TenantMetadata } from '../models/TenantMetadataModel';
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class TenantRepository extends TenantBaseRepository {
|
export class TenantRepository extends TenantBaseRepository {
|
||||||
constructor(
|
constructor(
|
||||||
|
private readonly configService: ConfigService,
|
||||||
|
|
||||||
@Inject(SystemKnexConnection)
|
@Inject(SystemKnexConnection)
|
||||||
private readonly tenantDBKnex: Knex,
|
private readonly tenantDBKnex: Knex,
|
||||||
|
|
||||||
@Inject(TenantMetadata.name)
|
@Inject(TenantMetadata.name)
|
||||||
private readonly tenantMetadataModel: typeof TenantMetadata,
|
private readonly tenantMetadataModel: typeof TenantMetadata,
|
||||||
|
|
||||||
private readonly configService: ConfigService,
|
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ import { Module } from '@nestjs/common';
|
|||||||
import { TenantsManagerService } from './TenantsManager';
|
import { TenantsManagerService } from './TenantsManager';
|
||||||
import { TenantDBManager } from './TenantDBManager';
|
import { TenantDBManager } from './TenantDBManager';
|
||||||
|
|
||||||
@Module({})
|
@Module({
|
||||||
export class TenantDBManagerModule {
|
providers: [TenantsManagerService, TenantDBManager],
|
||||||
providers: [TenantsManagerService, TenantDBManager];
|
exports: [TenantsManagerService, TenantDBManager],
|
||||||
}
|
})
|
||||||
|
export class TenantDBManagerModule {}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// @ts-nocheck
|
||||||
import { Knex, knex } from 'knex';
|
import { Knex, knex } from 'knex';
|
||||||
import { knexSnakeCaseMappers } from 'objection';
|
import { knexSnakeCaseMappers } from 'objection';
|
||||||
import { TenantDBAlreadyExists } from './exceptions/TenantDBAlreadyExists';
|
import { TenantDBAlreadyExists } from './exceptions/TenantDBAlreadyExists';
|
||||||
|
|||||||
Reference in New Issue
Block a user