mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 04:10:32 +00:00
35 lines
953 B
TypeScript
35 lines
953 B
TypeScript
import { Inject, Service } from 'typedi';
|
|
import HasTenancyService from '../Tenancy/TenancyService';
|
|
import { ImportFilePreviewPOJO } from './interfaces';
|
|
import { ImportFileProcess } from './ImportFileProcess';
|
|
|
|
@Service()
|
|
export class ImportFilePreview {
|
|
@Inject()
|
|
private tenancy: HasTenancyService;
|
|
|
|
@Inject()
|
|
private importFile: ImportFileProcess;
|
|
|
|
/**
|
|
* Preview the imported file results before commiting the transactions.
|
|
* @param {number} tenantId
|
|
* @param {number} importId
|
|
* @returns {Promise<ImportFilePreviewPOJO>}
|
|
*/
|
|
public async preview(
|
|
tenantId: number,
|
|
importId: string
|
|
): Promise<ImportFilePreviewPOJO> {
|
|
const knex = this.tenancy.knex(tenantId);
|
|
const trx = await knex.transaction({ isolationLevel: 'read uncommitted' });
|
|
|
|
const meta = await this.importFile.import(tenantId, importId, trx);
|
|
|
|
// Rollback the successed transaction.
|
|
await trx.rollback();
|
|
|
|
return meta;
|
|
}
|
|
}
|