overleaf/services/web/modules/server-ce-scripts/scripts/delete-user.js
Andrew Rumble b5cd5bd8fa Revert "[web] Migrate modules/server-ce-scripts to ESM"
GitOrigin-RevId: 61d971396b801e7bb3da1c5af7bd5ea4d91f3c9f
2024-10-22 08:07:04 +00:00

46 lines
1.1 KiB
JavaScript

const { waitForDb } = require('../../../app/src/infrastructure/mongodb')
const UserGetter = require('../../../app/src/Features/User/UserGetter')
const UserDeleter = require('../../../app/src/Features/User/UserDeleter')
async function main() {
await waitForDb()
const email = (process.argv.slice(2).pop() || '').replace(/^--email=/, '')
if (!email) {
console.error(`Usage: node ${__filename} --email=joe@example.com`)
process.exit(1)
}
await new Promise((resolve, reject) => {
UserGetter.getUser({ email }, { _id: 1 }, function (error, user) {
if (error) {
return reject(error)
}
if (!user) {
console.log(
`user ${email} not in database, potentially already deleted`
)
return resolve()
}
const options = {
ipAddress: '0.0.0.0',
}
UserDeleter.deleteUser(user._id, options, function (err) {
if (err) {
return reject(err)
}
resolve()
})
})
})
}
main()
.then(() => {
console.error('Done.')
process.exit(0)
})
.catch(err => {
console.error(err)
process.exit(1)
})