diff --git a/packages/server-nest/src/common/config/index.ts b/packages/server-nest/src/common/config/index.ts index 51acdceaa..9095c21db 100644 --- a/packages/server-nest/src/common/config/index.ts +++ b/packages/server-nest/src/common/config/index.ts @@ -12,6 +12,7 @@ import signupConfirmation from './signup-confirmation'; import signupRestrictions from './signup-restrictions'; import jwt from './jwt'; import mail from './mail'; +import loops from './loops'; export const config = [ systemDatabase, @@ -27,5 +28,6 @@ export const config = [ signupConfirmation, signupRestrictions, jwt, - mail + mail, + loops ]; diff --git a/packages/server-nest/src/common/config/loops.ts b/packages/server-nest/src/common/config/loops.ts new file mode 100644 index 000000000..294caacb5 --- /dev/null +++ b/packages/server-nest/src/common/config/loops.ts @@ -0,0 +1,6 @@ + +import { registerAs } from '@nestjs/config'; + +export default registerAs('loops', () => ({ + apiKey: process.env.LOOPS_API_KEY, +})); diff --git a/packages/server-nest/src/common/config/tenant-database.ts b/packages/server-nest/src/common/config/tenant-database.ts index 9e42808ff..8c25cdfb4 100644 --- a/packages/server-nest/src/common/config/tenant-database.ts +++ b/packages/server-nest/src/common/config/tenant-database.ts @@ -9,5 +9,5 @@ export default registerAs('tenantDatabase', () => ({ password: process.env.TENANT_DB_PASSWORD || process.env.DB_PASSWORD, dbNamePrefix: process.env.TENANT_DB_NAME_PERFIX || 'bigcapital_tenant_', migrationsDir: path.join(__dirname, '../../database/migrations'), - seedsDir: path.join(__dirname, '../../database/seeds'), + seedsDir: path.join(__dirname, '../../database/seeds/core'), })); diff --git a/packages/server-nest/src/database/seeds/core/20190423085242_seed_accounts.ts b/packages/server-nest/src/database/seeds/core/20190423085242_seed_accounts.ts index f3af3f1c3..303a4281a 100644 --- a/packages/server-nest/src/database/seeds/core/20190423085242_seed_accounts.ts +++ b/packages/server-nest/src/database/seeds/core/20190423085242_seed_accounts.ts @@ -1,5 +1,5 @@ import { TenantSeeder } from '@/libs/migration-seed/TenantSeeder'; -import AccountsData from '../data/accounts'; +import { AccountsData } from '../data/accounts'; export default class SeedAccounts extends TenantSeeder { /** @@ -8,8 +8,8 @@ export default class SeedAccounts extends TenantSeeder { up(knex) { const data = AccountsData.map((account) => ({ ...account, - name: this.i18n.__(account.name), - description: this.i18n(account.description), + name: this.i18n.t(account.name), + description: account.description ? this.i18n.t(account.description) : '', currencyCode: this.tenant.metadata.baseCurrency, seededAt: new Date(), })); diff --git a/packages/server-nest/src/database/seeds/data/accounts.js b/packages/server-nest/src/database/seeds/data/accounts.ts similarity index 98% rename from packages/server-nest/src/database/seeds/data/accounts.js rename to packages/server-nest/src/database/seeds/data/accounts.ts index 35430bbed..50a46ee85 100644 --- a/packages/server-nest/src/database/seeds/data/accounts.js +++ b/packages/server-nest/src/database/seeds/data/accounts.ts @@ -25,6 +25,7 @@ export const UnearnedRevenueAccount = { slug: 'unearned-revenue', account_type: 'other-current-liability', parent_account_id: null, + description: '', code: '50005', active: true, index: 1, @@ -36,6 +37,7 @@ export const PrepardExpenses = { slug: 'prepaid-expenses', account_type: 'other-current-asset', parent_account_id: null, + description: '', code: '100010', active: true, index: 1, @@ -47,6 +49,7 @@ export const StripeClearingAccount = { slug: 'stripe-clearing', account_type: 'other-current-asset', parent_account_id: null, + description: '', code: '100020', active: true, index: 1, @@ -57,6 +60,7 @@ export const DiscountExpenseAccount = { name: 'Discount', slug: 'discount', account_type: 'other-income', + description: '', code: '40008', active: true, index: 1, @@ -67,6 +71,7 @@ export const PurchaseDiscountAccount = { name: 'Purchase Discount', slug: 'purchase-discount', account_type: 'other-expense', + description: '', code: '40009', active: true, index: 1, @@ -77,13 +82,14 @@ export const OtherChargesAccount = { name: 'Other Charges', slug: 'other-charges', account_type: 'other-income', + description: '', code: '40010', active: true, index: 1, predefined: true, }; -export default [ +export const AccountsData = [ { name: 'Bank Account', slug: 'bank-account', diff --git a/packages/server-nest/src/libs/migration-seed/FsMigrations.ts b/packages/server-nest/src/libs/migration-seed/FsMigrations.ts index 4e607f2cf..f5785e857 100644 --- a/packages/server-nest/src/libs/migration-seed/FsMigrations.ts +++ b/packages/server-nest/src/libs/migration-seed/FsMigrations.ts @@ -1,6 +1,6 @@ -import path from 'path'; +import * as path from 'path'; +import * as fs from 'fs'; import { sortBy } from 'lodash'; -import fs from 'fs'; import { promisify } from 'util'; import { MigrateItem } from './interfaces'; import { importWebpackSeedModule } from './Utils'; @@ -93,7 +93,7 @@ class FsMigrations { * @returns {string} */ public getMigration(migration: MigrateItem): string { - return importWebpackSeedModule(migration.file); + return importWebpackSeedModule(migration.file.replace('.ts', '')); } } diff --git a/packages/server-nest/src/libs/migration-seed/MigrateUtils.ts b/packages/server-nest/src/libs/migration-seed/MigrateUtils.ts index 35feab077..0954258fb 100644 --- a/packages/server-nest/src/libs/migration-seed/MigrateUtils.ts +++ b/packages/server-nest/src/libs/migration-seed/MigrateUtils.ts @@ -1,6 +1,6 @@ // @ts-nocheck import { differenceWith } from 'lodash'; -import path from 'path'; +import * as path from 'path'; import { FsMigrations } from './FsMigrations'; import { getTable, diff --git a/packages/server-nest/src/libs/migration-seed/SeedMigration.ts b/packages/server-nest/src/libs/migration-seed/SeedMigration.ts index d87fc10be..6c8cfa931 100644 --- a/packages/server-nest/src/libs/migration-seed/SeedMigration.ts +++ b/packages/server-nest/src/libs/migration-seed/SeedMigration.ts @@ -1,6 +1,6 @@ // @ts-nocheck import { Knex } from 'knex'; -import Bluebird from 'bluebird'; +import * as Bluebird from 'bluebird'; import { getTable, getTableName, getLockTableName } from './TableUtils'; import getMergedConfig from './SeederConfig'; import { diff --git a/packages/server-nest/src/libs/migration-seed/SeederConfig.ts b/packages/server-nest/src/libs/migration-seed/SeederConfig.ts index 77ea2e57d..465e6522f 100644 --- a/packages/server-nest/src/libs/migration-seed/SeederConfig.ts +++ b/packages/server-nest/src/libs/migration-seed/SeederConfig.ts @@ -3,7 +3,7 @@ import { DEFAULT_LOAD_EXTENSIONS, FsMigrations } from './FsMigrations'; const CONFIG_DEFAULT = Object.freeze({ extension: 'js', loadExtensions: DEFAULT_LOAD_EXTENSIONS, - tableName: 'knex_migrations', + tableName: 'bigcapital_seeds', schemaName: null, directory: './migrations', disableTransactions: false, diff --git a/packages/server-nest/src/libs/migration-seed/TenantSeeder.ts b/packages/server-nest/src/libs/migration-seed/TenantSeeder.ts index 860923328..f36e1d51b 100644 --- a/packages/server-nest/src/libs/migration-seed/TenantSeeder.ts +++ b/packages/server-nest/src/libs/migration-seed/TenantSeeder.ts @@ -1,9 +1,10 @@ // @ts-nocheck +import { I18nService } from 'nestjs-i18n'; import { Seeder } from './Seeder'; export class TenantSeeder extends Seeder { public knex: any; - public i18n: i18nAPI; + public i18n: I18nService; public models: any; public tenant: any; diff --git a/packages/server-nest/src/libs/migration-seed/Utils.ts b/packages/server-nest/src/libs/migration-seed/Utils.ts index 6734d463c..d6f99b1de 100644 --- a/packages/server-nest/src/libs/migration-seed/Utils.ts +++ b/packages/server-nest/src/libs/migration-seed/Utils.ts @@ -1,5 +1,5 @@ // @ts-nocheck -import fs from 'fs'; +import * as fs from 'fs'; /** * Detarmines the module type of the given file path. @@ -38,5 +38,5 @@ export async function importFile(filepath: string): any { * @returns */ export async function importWebpackSeedModule(moduleName: string): any { - return import(`@/database/seeds/core/${moduleName}`); + return import(`../../database/seeds/core/${moduleName}`); } diff --git a/packages/server-nest/src/modules/Organization/commands/BuildOrganization.service.ts b/packages/server-nest/src/modules/Organization/commands/BuildOrganization.service.ts index 06e792d20..1d0c9e0ed 100644 --- a/packages/server-nest/src/modules/Organization/commands/BuildOrganization.service.ts +++ b/packages/server-nest/src/modules/Organization/commands/BuildOrganization.service.ts @@ -46,6 +46,7 @@ export class BuildOrganizationService { await this.tenantsManager.dropDatabaseIfExists(); await this.tenantsManager.createDatabase(); + await this.tenantsManager.migrateTenant(); await this.tenantsManager.seedTenant() diff --git a/packages/server-nest/src/modules/TenantDBManager/TenantDBManager.ts b/packages/server-nest/src/modules/TenantDBManager/TenantDBManager.ts index cbfbda1da..b7c6ea8ad 100644 --- a/packages/server-nest/src/modules/TenantDBManager/TenantDBManager.ts +++ b/packages/server-nest/src/modules/TenantDBManager/TenantDBManager.ts @@ -104,7 +104,7 @@ export class TenantDBManager { * @return {Promise} */ public async seed(): Promise { - await this.systemKnex.migrate.latest({ + await this.tenantKnex().migrate.latest({ ...tenantSeedConfig(tenant), disableMigrationsListValidation: true, }); diff --git a/packages/server-nest/src/modules/TenantDBManager/TenantsManager.ts b/packages/server-nest/src/modules/TenantDBManager/TenantsManager.ts index dbd2e8138..db4c77cd3 100644 --- a/packages/server-nest/src/modules/TenantDBManager/TenantsManager.ts +++ b/packages/server-nest/src/modules/TenantDBManager/TenantsManager.ts @@ -120,7 +120,7 @@ export class TenantsManagerService { * @returns */ public async getSeedMigrationContext() { - const tenant = await this.tenancyContext.getTenant(); + const tenant = await this.tenancyContext.getTenant(true); return { knex: this.tenantKnex(),