import { Knex } from 'knex'; import * as Yup from 'yup'; import { ImportableContext } from './interfaces'; export abstract class Importable { /** * * @param {number} tenantId * @param {any} createDTO * @param {Knex.Transaction} trx */ public importable(tenantId: number, createDTO: any, trx?: Knex.Transaction) { throw new Error( 'The `importable` function is not defined in service importable.' ); } /** * Transformes the DTO before passing it to importable and validation. * @param {Record} createDTO * @param {ImportableContext} context * @returns {Record} */ public transform(createDTO: Record, context: ImportableContext) { return createDTO; } /** * Concurrency controlling of the importing process. * @returns {number} */ public get concurrency() { return 10; } /** * Retrieves the sample data of importable. * @returns {Array} */ public sampleData(): Array { return []; } // ------------------ // # Params // ------------------ /** * Params Yup validation schema. * @returns {Yup.ObjectSchema} */ public paramsValidationSchema(): Yup.ObjectSchema { return Yup.object().nullable(); } /** * Validates the params of the importable service. * @param {Record} * @returns {Promise} - True means passed and false failed. */ public async validateParams( tenantId: number, params: Record ): Promise {} /** * Transformes the import params before storing them. * @param {Record} parmas */ public transformParams(parmas: Record) { return parmas; } }