Last active
February 15, 2024 17:09
-
-
Save enriquebeta6/feda3d2e697e404187391afa23c135c3 to your computer and use it in GitHub Desktop.
MasterData Utils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function deleteAll(entity) { | |
const sleep = (ms) => { | |
return new Promise((resolve) => { | |
setTimeout(resolve, ms) | |
}) | |
} | |
while (true) { | |
const randomNumber = Math.ceil(Math.random() * 100000) | |
const response = await fetch(`/api/dataentities/${entity}/search?_fields=id&_v=${randomNumber}`, { | |
headers: { | |
'REST-Range': 'resources=0-100', | |
} | |
}) | |
const documents = await response.json() | |
if (documents.length === 0) { | |
break; | |
} | |
await Promise.allSettled(documents.map(({ id }) => { | |
return fetch(`/api/dataentities/${entity}/documents/${id}`, { | |
method: 'DELETE', | |
}) | |
})) | |
await sleep(2000) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment