mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #3895 from overleaf/ta-delete-subscriptions-script
Add Script to Delete Subscriptions GitOrigin-RevId: fb8eda38f89c897cbd4c6d8bdcba19171b5914d3
This commit is contained in:
parent
3002a34cd3
commit
d7542e60c3
1 changed files with 49 additions and 0 deletions
49
services/web/scripts/delete_subscriptions.js
Normal file
49
services/web/scripts/delete_subscriptions.js
Normal file
|
@ -0,0 +1,49 @@
|
|||
const { Subscription } = require('../app/src/models/Subscription')
|
||||
const SubscriptionUpdater = require('../app/src/Features/Subscription/SubscriptionUpdater')
|
||||
const minimist = require('minimist')
|
||||
|
||||
const { waitForDb } = require('../app/src/infrastructure/mongodb')
|
||||
const { ObjectId } = require('mongodb')
|
||||
|
||||
const run = async () => {
|
||||
for (const id of ids) {
|
||||
console.log('id', id)
|
||||
const subscription = await Subscription.findOne({ _id: ObjectId(id) })
|
||||
await SubscriptionUpdater.promises.deleteSubscription(
|
||||
subscription,
|
||||
deleterData
|
||||
)
|
||||
console.log('Deleted subscription', id)
|
||||
}
|
||||
}
|
||||
|
||||
let ids, deleterData
|
||||
const setup = () => {
|
||||
const argv = minimist(process.argv.slice(2))
|
||||
ids = argv.ids
|
||||
if (!ids) {
|
||||
console.error('No ids given')
|
||||
process.exit(1)
|
||||
}
|
||||
ids = ids.split(',')
|
||||
|
||||
const deleterId = argv.deleterId
|
||||
if (!deleterId) {
|
||||
console.error('No deleterId given')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
deleterData = { id: ObjectId(deleterId) }
|
||||
}
|
||||
|
||||
setup()
|
||||
|
||||
waitForDb()
|
||||
.then(run)
|
||||
.then(() => {
|
||||
process.exit(0)
|
||||
})
|
||||
.catch(err => {
|
||||
console.log('Aiee, something went wrong!', err)
|
||||
process.exit(1)
|
||||
})
|
Loading…
Reference in a new issue