overleaf/services/web/scripts/clear_institution_notifications.mjs
Liangjun Song 26f3f3e2e2 Merge pull request #21097 from overleaf/ls-scripts-to-esm-1
Migrate scripts folder to esm 1/x

GitOrigin-RevId: 4a4bc9a161f144fdb40ce3f2a0a9313b36c6df81
2024-10-21 08:04:42 +00:00

49 lines
1.3 KiB
JavaScript

import { promisify } from 'util'
import InstitutionsManager from '../app/src/Features/Institutions/InstitutionsManager.js'
import { fileURLToPath } from 'url'
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)
const preview =
await InstitutionsManager.promises.clearInstitutionNotifications(
institutionId,
true
)
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)
const cleared =
await InstitutionsManager.promises.clearInstitutionNotifications(
institutionId,
false
)
console.log('--- Cleared ---')
console.log(JSON.stringify(cleared, null, 4))
console.log('---------------')
}
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)
}
}