Skip to content

Instantly share code, notes, and snippets.

@enriquebeta6
Last active February 15, 2024 17:09
Show Gist options
  • Save enriquebeta6/feda3d2e697e404187391afa23c135c3 to your computer and use it in GitHub Desktop.
Save enriquebeta6/feda3d2e697e404187391afa23c135c3 to your computer and use it in GitHub Desktop.
MasterData Utils
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