mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
fix: import resource imporements
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Knex } from 'knex';
|
||||
import { Inject, Service } from 'typedi';
|
||||
import HasTenancyService from '../Tenancy/TenancyService';
|
||||
import UnitOfWork, { IsolationLevel } from '../UnitOfWork';
|
||||
import { Knex } from 'knex';
|
||||
import UnitOfWork from '../UnitOfWork';
|
||||
import { CreateUncategorizedTransactionDTO } from '@/interfaces';
|
||||
|
||||
@Service()
|
||||
@@ -19,10 +19,10 @@ export class CreateUncategorizedTransaction {
|
||||
*/
|
||||
public create(
|
||||
tenantId: number,
|
||||
createDTO: CreateUncategorizedTransactionDTO
|
||||
createDTO: CreateUncategorizedTransactionDTO,
|
||||
trx?: Knex.Transaction
|
||||
) {
|
||||
const { UncategorizedCashflowTransaction, Account } =
|
||||
this.tenancy.models(tenantId);
|
||||
const { UncategorizedCashflowTransaction } = this.tenancy.models(tenantId);
|
||||
|
||||
return this.uow.withTransaction(
|
||||
tenantId,
|
||||
@@ -32,9 +32,9 @@ export class CreateUncategorizedTransaction {
|
||||
).insertAndFetch({
|
||||
...createDTO,
|
||||
});
|
||||
|
||||
return transaction;
|
||||
},
|
||||
trx
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { Knex } from 'knex';
|
||||
import * as yup from 'yup';
|
||||
import { Importable } from '../Import/Importable';
|
||||
import { CreateUncategorizedTransaction } from './CreateUncategorizedTransaction';
|
||||
import { CreateUncategorizedTransactionDTO } from '@/interfaces';
|
||||
import { ImportableContext } from '../Import/interfaces';
|
||||
import HasTenancyService from '../Tenancy/TenancyService';
|
||||
import { ImportSampleData } from './constants';
|
||||
|
||||
@Service()
|
||||
export class UncategorizedTransactionsImportable extends Importable {
|
||||
@Inject()
|
||||
private createUncategorizedTransaction: CreateUncategorizedTransaction;
|
||||
|
||||
@Inject()
|
||||
private tenancy: HasTenancyService;
|
||||
/**
|
||||
* Passing the sheet DTO to create uncategorized transaction.
|
||||
* @param {number} tenantId
|
||||
* @param {number} tenantId
|
||||
* @param {any} createDTO
|
||||
* @param {Knex.Transaction} trx
|
||||
*/
|
||||
public async importable(
|
||||
tenantId: number,
|
||||
createDTO: CreateUncategorizedTransactionDTO,
|
||||
trx?: Knex.Transaction
|
||||
) {
|
||||
return this.createUncategorizedTransaction.create(tenantId, createDTO, trx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transformes the DTO before validating and importing.
|
||||
* @param {CreateUncategorizedTransactionDTO} createDTO
|
||||
* @param {ImportableContext} context
|
||||
* @returns {CreateUncategorizedTransactionDTO}
|
||||
*/
|
||||
public transform(
|
||||
createDTO: CreateUncategorizedTransactionDTO,
|
||||
context?: ImportableContext
|
||||
): CreateUncategorizedTransactionDTO {
|
||||
return {
|
||||
...createDTO,
|
||||
accountId: context.import.paramsParsed.accountId,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Sample data used to download sample sheet.
|
||||
* @returns {Record<string, any>[]}
|
||||
*/
|
||||
public sampleData(): Record<string, any>[] {
|
||||
return ImportSampleData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Params validation schema.
|
||||
* @returns {ValidationSchema[]}
|
||||
*/
|
||||
public paramsValidationSchema() {
|
||||
return yup.object().shape({
|
||||
accountId: yup.number().required(),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the params existance asyncly.
|
||||
* @param {number} tenantId -
|
||||
* @param {Record<string, any>} params -
|
||||
*/
|
||||
public async validateParams(
|
||||
tenantId: number,
|
||||
params: Record<string, any>
|
||||
): Promise<void> {
|
||||
const { Account } = this.tenancy.models(tenantId);
|
||||
|
||||
if (params.accountId) {
|
||||
await Account.query()
|
||||
.findById(params.accountId)
|
||||
.throwIfNotFound({});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,3 +75,25 @@ export interface ICashflowTransactionTypeMeta {
|
||||
direction: CASHFLOW_DIRECTION;
|
||||
creditType: string[];
|
||||
}
|
||||
|
||||
|
||||
export const ImportSampleData = [
|
||||
{
|
||||
Amount: 5000,
|
||||
Date: '2024-01-01',
|
||||
Payee: 'John Roberts',
|
||||
Description: 'Cheque deposit',
|
||||
},
|
||||
{
|
||||
Amount: 5000,
|
||||
Date: '2024-01-01',
|
||||
Payee: 'John Roberts',
|
||||
Description: 'Cheque deposit',
|
||||
},
|
||||
{
|
||||
Amount: 5000,
|
||||
Date: '2024-01-01',
|
||||
Payee: 'John Roberts',
|
||||
Description: 'Cheque deposit',
|
||||
},
|
||||
]
|
||||
Reference in New Issue
Block a user