Skip to content

Commit

Permalink
new import/export command - disable webhooks optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
KarolNet committed Nov 28, 2024
1 parent f9540aa commit 2374acf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
36 changes: 18 additions & 18 deletions commands/importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,21 @@ async function importer(directory, flotiqApiUrl, flotiqApiKey, skipDefinitions,
batchSize: BATCH_SIZE,
});

try {
await fs.stat(path.resolve(directory))

} catch (e) {
logger.error(`Cannot open import dir ${directory}`)
return false;
}

const headers = {
'Content-type': 'application/json;charset=utf-8',
'X-Auth-Token': flotiqApiKey
}

let existingWebhooks = [];
if (disableWebhooks) {
let existingWebhooks = await flotiqApi.fetchContentObjects('_webhooks');
logger.info(`Pass 1a - disable webhooks`);
await flotiqApi.patchContentObjectBatch('_webhooks', existingWebhooks.map(webhook => ({
id: webhook.id,
enabled: false
})));
}

const CTDFiles = await glob(`${directory}/**/ContentTypeDefinition.json`)

let CTDs = await Promise.all(
Expand Down Expand Up @@ -223,16 +225,6 @@ async function importer(directory, flotiqApiUrl, flotiqApiKey, skipDefinitions,
}
}

const existingWebhooks = await flotiqApi.fetchContentObjects('_webhooks');

if (disableWebhooks) {
logger.info(`Pass 1a - disable webhooks`);
await flotiqApi.patchContentObjectBatch('_webhooks', existingWebhooks.map(webhook => ({
id: webhook.id,
enabled: false
})));
}

if (skipContent) {
logger.info('All done')
return
Expand Down Expand Up @@ -461,6 +453,14 @@ async function main(argv) {
return false;
}

try {
await fs.stat(path.resolve(argv.directory))

} catch (e) {
logger.error(`Cannot open import dir ${argv.directory}`)
return false;
}

await importer(
argv.directory,
`${config.apiUrl}/api/v1`,
Expand Down
4 changes: 1 addition & 3 deletions tests/commands/importer.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const fs = require('fs/promises');
const path = require('path');
const glob = require('glob');
const fetch = require('node-fetch');
const FlotiqApi = require('./../../src/flotiq-api');
Expand Down Expand Up @@ -57,8 +56,7 @@ describe('importer', () => {
importer(mockDirectory, mockApiUrl, mockApiKey, false, false, true, false, false)
).resolves.not.toThrow();

// Assertions
expect(fs.stat).toHaveBeenCalledWith(path.resolve(mockDirectory));

expect(fetch).toHaveBeenCalled();
expect(FlotiqApi).toHaveBeenCalledWith(mockApiUrl, mockApiKey, expect.any(Object));
});
Expand Down

0 comments on commit 2374acf

Please sign in to comment.