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