refactor: wip migrate ot nestjs

This commit is contained in:
Ahmed Bouhuolia
2024-12-19 12:48:24 +02:00
parent bfff56c470
commit 93bf6d9d3d
73 changed files with 4683 additions and 96 deletions

View File

@@ -1,11 +1,9 @@
// import { IAccountsStructureType } from './Accounts.types';
// import {
// assocDepthLevelToObjectTree,
// flatToNestedArray,
// nestedArrayToFlatten,
// } from 'utils';
import { Transformer } from '../Transformer/Transformer';
import { AccountModel } from './models/Account.model';
import { flatToNestedArray } from '@/utils/flat-to-nested-array';
import { assocDepthLevelToObjectTree } from '@/utils/assoc-depth-level-to-object-tree';
import { nestedArrayToFlatten } from '@/utils/nested-array-to-flatten';
import { IAccountsStructureType } from './Accounts.types';
export class AccountTransformer extends Transformer {
/**
@@ -113,20 +111,20 @@ export class AccountTransformer extends Transformer {
* @param {IAccount[]}
* @returns {IAccount[]}
*/
// protected postCollectionTransform = (accounts: AccountModel[]) => {
// // Transfom the flatten to accounts tree.
// const transformed = flatToNestedArray(accounts, {
// id: 'id',
// parentId: 'parentAccountId',
// });
// // Associate `accountLevel` attr to indicate object depth.
// const transformed2 = assocDepthLevelToObjectTree(
// transformed,
// 1,
// 'accountLevel',
// );
// return this.options.structure === IAccountsStructureType.Flat
// ? nestedArrayToFlatten(transformed2)
// : transformed2;
// };
protected postCollectionTransform = (accounts: AccountModel[]) => {
// Transfom the flatten to accounts tree.
const transformed = flatToNestedArray(accounts, {
id: 'id',
parentId: 'parentAccountId',
});
// Associate `accountLevel` attr to indicate object depth.
const transformed2 = assocDepthLevelToObjectTree(
transformed,
1,
'accountLevel',
);
return this.options.structure === IAccountsStructureType.Flat
? nestedArrayToFlatten(transformed2)
: transformed2;
};
}

View File

@@ -32,7 +32,6 @@ import { GetAccountTransactionsService } from './GetAccountTransactions.service'
ActivateAccount,
GetAccountTypesService,
GetAccountTransactionsService,
// GetAccountsService,
],
})
export class AccountsModule {}

View File

@@ -1,20 +1,8 @@
import { Knex } from 'knex';
import { Injectable } from '@nestjs/common';
// import {
// IAccount,
// IAccountCreateDTO,
// IAccountEditDTO,
// IAccountResponse,
// IAccountsFilter,
// IAccountsTransactionsFilter,
// IFilterMeta,
// IGetAccountTransactionPOJO,
// } from '@/interfaces';
import { CreateAccountService } from './CreateAccount.service';
import { DeleteAccount } from './DeleteAccount.service';
import { EditAccount } from './EditAccount.service';
// import { GetAccounts } from './GetAccounts.service';
// import { GetAccountTransactions } from './GetAccountTransactions.service';
import { CreateAccountDTO } from './CreateAccount.dto';
import { AccountModel } from './models/Account.model';
import { EditAccountDTO } from './EditAccount.dto';
@@ -31,8 +19,8 @@ import {
export class AccountsApplication {
constructor(
private readonly createAccountService: CreateAccountService,
private readonly deleteAccountService: DeleteAccount,
private readonly editAccountService: EditAccount,
private readonly deleteAccountService: DeleteAccount,
private readonly activateAccountService: ActivateAccount,
private readonly getAccountTypesService: GetAccountTypesService,
private readonly getAccountService: GetAccount,

View File

@@ -4,20 +4,19 @@
// IAccountsFilter,
// IAccountResponse,
// IFilterMeta,
// } from '@/interfaces';
// import { DynamicListingService } from '@/services/DynamicListing/DynamicListService';
// } from './Accounts.types';
// import { DynamicListService } from '../DynamicListing/DynamicListService';
// import { AccountTransformer } from './Account.transformer';
// import { TransformerService } from '@/lib/Transformer/TransformerService';
// import { flatToNestedArray } from '@/utils';
// import { Account } from './Account.model';
// import { TransformerInjectable } from '../Transformer/TransformerInjectable.service';
// import { AccountModel } from './models/Account.model';
// import { AccountRepository } from './repositories/Account.repository';
// @Injectable()
// export class GetAccountsService {
// constructor(
// private readonly dynamicListService: DynamicListingService,
// private readonly transformerService: TransformerService,
// private readonly accountModel: typeof Account,
// private readonly dynamicListService: DynamicListService,
// private readonly transformerService: TransformerInjectable,
// private readonly accountModel: typeof AccountModel,
// private readonly accountRepository: AccountRepository,
// ) {}

View File

@@ -11,6 +11,7 @@ import { TenantModel } from '@/modules/System/models/TenantModel';
// import { CustomViewBaseModel } from '@/modules/CustomViews/CustomViewBaseModel';
// import { ModelSettings } from '@/modules/Settings/ModelSettings';
import { AccountTypesUtils } from '@/libs/accounts-utils/AccountTypesUtils';
import { Model } from 'objection';
// import AccountSettings from './Account.Settings';
// import { DEFAULT_VIEWS } from '@/modules/Accounts/constants';
// import { buildFilterQuery, buildSortColumnQuery } from '@/lib/ViewRolesBuilder';
@@ -204,50 +205,50 @@ export class AccountModel extends TenantModel {
* Relationship mapping.
*/
static get relationMappings() {
// const AccountTransaction = require('models/AccountTransaction');
// const Item = require('models/Item');
const { AccountTransaction } = require('./AccountTransaction.model');
const { Item } = require('../../Items/models/Item');
// const InventoryAdjustment = require('models/InventoryAdjustment');
// const ManualJournalEntry = require('models/ManualJournalEntry');
// const Expense = require('models/Expense');
// const ExpenseEntry = require('models/ExpenseCategory');
// const ItemEntry = require('models/ItemEntry');
// const UncategorizedTransaction = require('models/UncategorizedCashflowTransaction');
// const PlaidItem = require('models/PlaidItem');
const { PlaidItem } = require('../../Banking/models/PlaidItem.model');
return {
// /**
// * Account model may has many transactions.
// */
// transactions: {
// relation: Model.HasManyRelation,
// modelClass: AccountTransaction.default,
// join: {
// from: 'accounts.id',
// to: 'accounts_transactions.accountId',
// },
// },
// /**
// *
// */
// itemsCostAccount: {
// relation: Model.HasManyRelation,
// modelClass: Item.default,
// join: {
// from: 'accounts.id',
// to: 'items.costAccountId',
// },
// },
// /**
// *
// */
// itemsSellAccount: {
// relation: Model.HasManyRelation,
// modelClass: Item.default,
// join: {
// from: 'accounts.id',
// to: 'items.sellAccountId',
// },
// },
/**
* Account model may has many transactions.
*/
transactions: {
relation: Model.HasManyRelation,
modelClass: AccountTransaction,
join: {
from: 'accounts.id',
to: 'accounts_transactions.accountId',
},
},
/**
* Account may has many items as cost account.
*/
itemsCostAccount: {
relation: Model.HasManyRelation,
modelClass: Item,
join: {
from: 'accounts.id',
to: 'items.costAccountId',
},
},
/**
* Account may has many items as sell account.
*/
itemsSellAccount: {
relation: Model.HasManyRelation,
modelClass: Item,
join: {
from: 'accounts.id',
to: 'items.sellAccountId',
},
},
// /**
// *
// */
@@ -328,17 +329,17 @@ export class AccountModel extends TenantModel {
// query.where('categorized', false);
// },
// },
// /**
// * Account model may belongs to a Plaid item.
// */
// plaidItem: {
// relation: Model.BelongsToOneRelation,
// modelClass: PlaidItem.default,
// join: {
// from: 'accounts.plaidItemId',
// to: 'plaid_items.plaidItemId',
// },
// },
/**
* Account model may belongs to a Plaid item.
*/
plaidItem: {
relation: Model.BelongsToOneRelation,
modelClass: PlaidItem,
join: {
from: 'accounts.plaidItemId',
to: 'plaid_items.plaidItemId',
},
},
};
}