2024-10-21 11:56:13 -04:00
|
|
|
const { waitForDb } = require('../../../app/src/infrastructure/mongodb')
|
|
|
|
const UserGetter = require('../../../app/src/Features/User/UserGetter')
|
|
|
|
const UserDeleter = require('../../../app/src/Features/User/UserDeleter')
|
2021-07-14 06:55:08 -04:00
|
|
|
|
|
|
|
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) => {
|
2023-09-07 07:53:40 -04:00
|
|
|
UserGetter.getUser({ email }, { _id: 1 }, function (error, user) {
|
2021-07-14 06:55:08 -04:00
|
|
|
if (error) {
|
|
|
|
return reject(error)
|
|
|
|
}
|
|
|
|
if (!user) {
|
|
|
|
console.log(
|
|
|
|
`user ${email} not in database, potentially already deleted`
|
|
|
|
)
|
|
|
|
return resolve()
|
|
|
|
}
|
2024-02-02 05:23:33 -05:00
|
|
|
const options = {
|
|
|
|
ipAddress: '0.0.0.0',
|
|
|
|
}
|
|
|
|
UserDeleter.deleteUser(user._id, options, function (err) {
|
2021-07-14 06:55:08 -04:00
|
|
|
if (err) {
|
|
|
|
return reject(err)
|
|
|
|
}
|
|
|
|
resolve()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
main()
|
|
|
|
.then(() => {
|
|
|
|
console.error('Done.')
|
|
|
|
process.exit(0)
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.error(err)
|
|
|
|
process.exit(1)
|
|
|
|
})
|