feat: wip import resources

This commit is contained in:
Ahmed Bouhuolia
2024-03-15 00:18:41 +02:00
parent 084d9d3d10
commit ab4c0ab7a7
14 changed files with 96 additions and 125 deletions

View File

@@ -11,7 +11,7 @@ import {
ImportOperError,
ImportOperSuccess,
} from './interfaces';
import { AccountsImportable } from './AccountsImportable';
import { AccountsImportable } from '../Accounts/AccountsImportable';
import { ServiceError } from '@/exceptions';
import { trimObject } from './_utils';
import { ImportableResources } from './ImportableResources';
@@ -57,12 +57,12 @@ export class ImportFileCommon {
}
/**
*
* Imports the given parsed data to the resource storage through registered importable service.
* @param {number} tenantId -
* @param {string} resourceName - Resource name.
* @param {Record<string, any>} parsedData -
* @param {Knex.Transaction} trx
* @returns
* @param {Record<string, any>} parsedData - Parsed data.
* @param {Knex.Transaction} trx - Knex transaction.
* @returns {Promise<[ImportOperSuccess[], ImportOperError[]]>}
*/
public async import(
tenantId: number,
@@ -77,6 +77,8 @@ export class ImportFileCommon {
const ImportableRegistry = this.importable.registry;
const importable = ImportableRegistry.getImportable(resourceName);
const concurrency = importable.concurrency || 10;
const success: ImportOperSuccess[] = [];
const failed: ImportOperError[] = [];
@@ -108,7 +110,7 @@ export class ImportFileCommon {
failed.push({ index, error });
}
};
await bluebird.map(parsedData, importAsync, { concurrency: 2 });
await bluebird.map(parsedData, importAsync, { concurrency });
return [success, failed];
}
@@ -127,7 +129,7 @@ export class ImportFileCommon {
* @param {number} tenantId
* @param {} importFile
*/
private async deleteImportFile(tenantId: number, importFile: any) {
public async deleteImportFile(tenantId: number, importFile: any) {
const { Import } = this.tenancy.models(tenantId);
// Deletes the import row.