2024-10-18 07:04:57 -04:00
|
|
|
import { Subscription } from '../app/src/models/Subscription.js'
|
|
|
|
import SubscriptionUpdater from '../app/src/Features/Subscription/SubscriptionUpdater.js'
|
|
|
|
import minimist from 'minimist'
|
|
|
|
import mongodb from 'mongodb-legacy'
|
2021-04-14 05:00:18 -04:00
|
|
|
|
2024-10-18 07:04:57 -04:00
|
|
|
const { ObjectId } = mongodb
|
2021-04-14 05:00:18 -04:00
|
|
|
|
|
|
|
const run = async () => {
|
|
|
|
for (const id of ids) {
|
|
|
|
console.log('id', id)
|
2023-12-18 05:54:01 -05:00
|
|
|
const subscription = await Subscription.findOne({ _id: new ObjectId(id) })
|
2021-04-14 05:00:18 -04:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2023-12-18 05:54:01 -05:00
|
|
|
deleterData = { id: new ObjectId(deleterId) }
|
2021-04-14 05:00:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
setup()
|
|
|
|
|
2024-10-31 08:16:54 -04:00
|
|
|
try {
|
|
|
|
await run()
|
|
|
|
process.exit(0)
|
|
|
|
} catch (err) {
|
|
|
|
console.error('Aiee, something went wrong!', err)
|
|
|
|
process.exit(1)
|
|
|
|
}
|