mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-01 06:15:07 -05:00
26f3f3e2e2
Migrate scripts folder to esm 1/x GitOrigin-RevId: 4a4bc9a161f144fdb40ce3f2a0a9313b36c6df81
50 lines
1.1 KiB
JavaScript
50 lines
1.1 KiB
JavaScript
import { Subscription } from '../app/src/models/Subscription.js'
|
|
import SubscriptionUpdater from '../app/src/Features/Subscription/SubscriptionUpdater.js'
|
|
import minimist from 'minimist'
|
|
import { waitForDb } from '../app/src/infrastructure/mongodb.js'
|
|
import mongodb from 'mongodb-legacy'
|
|
|
|
const { ObjectId } = mongodb
|
|
|
|
const run = async () => {
|
|
for (const id of ids) {
|
|
console.log('id', id)
|
|
const subscription = await Subscription.findOne({ _id: new 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: new ObjectId(deleterId) }
|
|
}
|
|
|
|
setup()
|
|
|
|
waitForDb()
|
|
.then(run)
|
|
.then(() => {
|
|
process.exit(0)
|
|
})
|
|
.catch(err => {
|
|
console.log('Aiee, something went wrong!', err)
|
|
process.exit(1)
|
|
})
|