diff --git a/packages/server/scripts/load/delete-all-apps.js b/packages/server/scripts/load/delete-all-apps.js new file mode 100755 index 0000000000..5c9e974c7d --- /dev/null +++ b/packages/server/scripts/load/delete-all-apps.js @@ -0,0 +1,29 @@ +#!/bin/node +const { searchApps, deleteApp } = require("./utils") + +if (!process.argv[2]) { + console.error("Please specify an API key as script argument.") + process.exit(-1) +} + +async function run() { + const apiKey = process.argv[2] + const apps = await searchApps(apiKey) + console.log(`Deleting ${apps.length} apps`) + + let deletedApps = 0 + await Promise.all( + apps.map(async app => { + await deleteApp(apiKey, app._id) + console.log(`App ${++deletedApps} of ${apps.length} deleted`) + }) + ) +} + +run() + .then(() => { + console.log("Done!") + }) + .catch(err => { + console.error(err) + }) diff --git a/packages/server/scripts/load/utils.js b/packages/server/scripts/load/utils.js index 7af867ab1d..04ebb6f3d6 100644 --- a/packages/server/scripts/load/utils.js +++ b/packages/server/scripts/load/utils.js @@ -38,6 +38,17 @@ exports.createApp = async apiKey => { return json.data } +exports.searchApps = async apiKey => { + const res = await request(apiKey, `${URL_APP}/search`, "POST", {}) + const json = await res.json() + return json.data +} + +exports.deleteApp = async (apiKey, appId) => { + const res = await request(apiKey, `${URL_APP}/${appId}`, "DELETE") + return res +} + exports.getTable = async (apiKey, appId) => { const res = await request(apiKey, URL_SEARCH_TABLE, "POST", {}, appId) const json = await res.json()