diff --git a/src/controllers/bulkUpload.ts b/src/controllers/bulkUpload.ts index dbd77dc07f..d29ef59314 100644 --- a/src/controllers/bulkUpload.ts +++ b/src/controllers/bulkUpload.ts @@ -5,7 +5,7 @@ import { getJobStatusHandler, getPollStatusHandler, getDestFileUploadHandler, -} from '../util/fetchDestinationHandlers'; +} from '../util/fetchBulkUploadHandlers'; import { CatchErr, ContextBodySimple } from '../util/types'; // TODO: To be refactored and redisgned diff --git a/src/util/fetchBulkUploadHandlers.ts b/src/util/fetchBulkUploadHandlers.ts new file mode 100644 index 0000000000..2661ef2e68 --- /dev/null +++ b/src/util/fetchBulkUploadHandlers.ts @@ -0,0 +1,42 @@ +import * as V0MarketoBulkUploadFileUpload from '../v0/destinations/marketo_bulk_upload/fileUpload'; +import * as V0MarketoBulkUploadPollStatus from '../v0/destinations/marketo_bulk_upload/poll'; +import * as V0MarketoBulkUploadJobStatus from '../v0/destinations/marketo_bulk_upload/fetchJobStatus'; + +const fileUploadHandlers = { + v0: { + marketo_bulk_upload: V0MarketoBulkUploadFileUpload, + }, +}; + +const pollStatusHandlers = { + v0: { + marketo_bulk_upload: V0MarketoBulkUploadPollStatus, + }, +}; + +const jobStatusHandlers = { + v0: { + marketo_bulk_upload: V0MarketoBulkUploadJobStatus, + }, +}; + +export const getDestFileUploadHandler = (version, dest) => { + if (fileUploadHandlers[version] && fileUploadHandlers[version][dest]) { + return fileUploadHandlers[version][dest]; + } + return undefined; +}; + +export const getPollStatusHandler = (version, dest) => { + if (pollStatusHandlers[version] && pollStatusHandlers[version][dest]) { + return pollStatusHandlers[version][dest]; + } + return undefined; +}; + +export const getJobStatusHandler = (version, dest) => { + if (jobStatusHandlers[version] && jobStatusHandlers[version][dest]) { + return jobStatusHandlers[version][dest]; + } + return undefined; +}; diff --git a/src/util/fetchDestinationHandlers.ts b/src/util/fetchDestinationHandlers.ts index bf0edd3e84..417ae7899a 100644 --- a/src/util/fetchDestinationHandlers.ts +++ b/src/util/fetchDestinationHandlers.ts @@ -1,14 +1,14 @@ /* eslint-disable import/no-dynamic-require,global-require */ -import fs from 'fs'; -import path from 'path'; -import { set } from 'lodash'; +const fs = require('fs'); +const path = require('path'); +const { set } = require('lodash'); // Define the directory path const destinationsPath = path.join(__dirname, '..', 'v0', 'destinations'); // Read the contents of the directory synchronously -const destinations: string[] = fs - .readdirSync(destinationsPath, { withFileTypes: true }) +const destinationsDirectories = fs.readdirSync(destinationsPath, { withFileTypes: true }); +const destinations = destinationsDirectories .filter((item) => item.isDirectory()) .map((item) => item.name); @@ -35,37 +35,45 @@ destinations.forEach((destination) => { }); }); -export const getDestFileUploadHandler = (version, dest) => { +const getDestFileUploadHandler = (version, dest) => { if (fileUploadHandlers[version] && fileUploadHandlers[version][dest]) { return fileUploadHandlers[version][dest]; } return undefined; }; -export const getPollStatusHandler = (version, dest) => { +const getPollStatusHandler = (version, dest) => { if (pollStatusHandlers[version] && pollStatusHandlers[version][dest]) { return pollStatusHandlers[version][dest]; } return undefined; }; -export const getJobStatusHandler = (version, dest) => { +const getJobStatusHandler = (version, dest) => { if (jobStatusHandlers[version] && jobStatusHandlers[version][dest]) { return jobStatusHandlers[version][dest]; } return undefined; }; -export const getDestTransformHandler = (version, dest) => { +const getDestTransformHandler = (version, dest) => { if (destinationHandlers[version] && destinationHandlers[version][dest]) { return destinationHandlers[version][dest]; } return undefined; }; -export const getDeletionUserHandler = (version, dest) => { +const getDeletionUserHandler = (version, dest) => { if (deleteUserHandlers[version] && deleteUserHandlers[version][dest]) { return deleteUserHandlers[version][dest]; } return undefined; }; + +module.exports = { + getDestTransformHandler, + getDeletionUserHandler, + getDestFileUploadHandler, + getPollStatusHandler, + getJobStatusHandler, +};