feat: import resources from csv/xlsx

This commit is contained in:
Ahmed Bouhuolia
2024-03-11 00:21:36 +02:00
parent 1fc6445123
commit 90b4f3ef6d
16 changed files with 467 additions and 184 deletions

View File

@@ -16,6 +16,7 @@ import { ActivateAccount } from './ActivateAccount';
import { GetAccounts } from './GetAccounts';
import { GetAccount } from './GetAccount';
import { GetAccountTransactions } from './GetAccountTransactions';
import { Knex } from 'knex';
@Service()
export class AccountsApplication {
@@ -48,9 +49,10 @@ export class AccountsApplication {
*/
public createAccount = (
tenantId: number,
accountDTO: IAccountCreateDTO
accountDTO: IAccountCreateDTO,
trx?: Knex.Transaction
): Promise<IAccount> => {
return this.createAccountService.createAccount(tenantId, accountDTO);
return this.createAccountService.createAccount(tenantId, accountDTO, trx);
};
/**

View File

@@ -97,13 +97,14 @@ export class CreateAccount {
/**
* Creates a new account on the storage.
* @param {number} tenantId
* @param {IAccountCreateDTO} accountDTO
* @param {number} tenantId
* @param {IAccountCreateDTO} accountDTO
* @returns {Promise<IAccount>}
*/
public createAccount = async (
tenantId: number,
accountDTO: IAccountCreateDTO
accountDTO: IAccountCreateDTO,
trx?: Knex.Transaction
): Promise<IAccount> => {
const { Account } = this.tenancy.models(tenantId);
@@ -119,27 +120,31 @@ export class CreateAccount {
tenantMeta.baseCurrency
);
// Creates a new account with associated transactions under unit-of-work envirement.
return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => {
// Triggers `onAccountCreating` event.
await this.eventPublisher.emitAsync(events.accounts.onCreating, {
tenantId,
accountDTO,
trx,
} as IAccountEventCreatingPayload);
return this.uow.withTransaction(
tenantId,
async (trx: Knex.Transaction) => {
// Triggers `onAccountCreating` event.
await this.eventPublisher.emitAsync(events.accounts.onCreating, {
tenantId,
accountDTO,
trx,
} as IAccountEventCreatingPayload);
// Inserts account to the storage.
const account = await Account.query(trx).insertAndFetch({
...accountInputModel,
});
// Triggers `onAccountCreated` event.
await this.eventPublisher.emitAsync(events.accounts.onCreated, {
tenantId,
account,
accountId: account.id,
trx,
} as IAccountEventCreatedPayload);
// Inserts account to the storage.
const account = await Account.query(trx).insertAndFetch({
...accountInputModel,
});
// Triggers `onAccountCreated` event.
await this.eventPublisher.emitAsync(events.accounts.onCreated, {
tenantId,
account,
accountId: account.id,
trx,
} as IAccountEventCreatedPayload);
return account;
});
return account;
},
trx
);
};
}

View File

@@ -1,15 +1,15 @@
import { DATATYPES_LENGTH } from '@/data/DataTypes';
import { IsInt, IsOptional, IsString, Length, Min, Max } from 'class-validator';
import { IsInt, IsOptional, IsString, Length, Min, Max, IsNotEmpty } from 'class-validator';
export class AccountDTOSchema {
@IsString()
@Length(3, DATATYPES_LENGTH.STRING)
@IsNotEmpty()
name: string;
// @IsString()
// @IsInt()
@IsString()
@IsOptional()
// @Length(3, 6)
@Length(3, 6)
code?: string;
@IsOptional()
@@ -17,6 +17,7 @@ export class AccountDTOSchema {
@IsString()
@Length(3, DATATYPES_LENGTH.STRING)
@IsNotEmpty()
accountType: string;
@IsString()