2024-11-04 04:09:11 -05:00
|
|
|
import { promisify } from 'node:util'
|
2024-10-18 07:04:57 -04:00
|
|
|
import InstitutionsManager from '../app/src/Features/Institutions/InstitutionsManager.js'
|
2024-11-04 04:09:11 -05:00
|
|
|
import { fileURLToPath } from 'node:url'
|
2021-10-20 06:18:14 -04:00
|
|
|
const sleep = promisify(setTimeout)
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
const institutionId = parseInt(process.argv[2])
|
|
|
|
if (isNaN(institutionId)) throw new Error('No institution id')
|
|
|
|
const dryRun = process.argv.includes('--dry-run')
|
|
|
|
|
|
|
|
console.log('Deleting notifications of institution', institutionId)
|
|
|
|
|
2022-01-10 05:23:05 -05:00
|
|
|
const preview =
|
|
|
|
await InstitutionsManager.promises.clearInstitutionNotifications(
|
|
|
|
institutionId,
|
|
|
|
true
|
|
|
|
)
|
2021-10-20 06:18:14 -04:00
|
|
|
console.log('--- Preview ---')
|
|
|
|
console.log(JSON.stringify(preview, null, 4))
|
|
|
|
console.log('---------------')
|
|
|
|
|
|
|
|
if (dryRun) {
|
|
|
|
console.log('Exiting early due to --dry-run flag')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('Exit in the next 10s in case these numbers are off.')
|
|
|
|
await sleep(10 * 1000)
|
|
|
|
|
2022-01-10 05:23:05 -05:00
|
|
|
const cleared =
|
|
|
|
await InstitutionsManager.promises.clearInstitutionNotifications(
|
|
|
|
institutionId,
|
|
|
|
false
|
|
|
|
)
|
2021-10-20 06:18:14 -04:00
|
|
|
console.log('--- Cleared ---')
|
|
|
|
console.log(JSON.stringify(cleared, null, 4))
|
|
|
|
console.log('---------------')
|
|
|
|
}
|
|
|
|
|
2024-10-18 07:04:57 -04:00
|
|
|
if (fileURLToPath(import.meta.url) === process.argv[1]) {
|
|
|
|
try {
|
|
|
|
await main()
|
|
|
|
console.log('Done.')
|
|
|
|
process.exit(0)
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error)
|
|
|
|
process.exit(1)
|
|
|
|
}
|
2021-10-20 06:18:14 -04:00
|
|
|
}
|