refresh_institution_users.mjs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { waitForDb } from '../app/src/infrastructure/mongodb.js'
  2. import minimist from 'minimist'
  3. import InstitutionsManager from '../app/src/Features/Institutions/InstitutionsManager.js'
  4. const institutionId = parseInt(process.argv[2])
  5. if (isNaN(institutionId)) throw new Error('No institution id')
  6. console.log('Refreshing users at institution', institutionId)
  7. function main() {
  8. const argv = minimist(process.argv.slice(2))
  9. if (!argv.notify) {
  10. throw new Error('Missing `notify` flag. Please use `--notify true|false`')
  11. }
  12. if (!argv.notify[0]) {
  13. throw new Error('Empty `notify` flag. Please use `--notify true|false`')
  14. }
  15. const notify = argv.notify[0] === 't'
  16. console.log('Running with notify =', notify)
  17. InstitutionsManager.refreshInstitutionUsers(
  18. institutionId,
  19. notify,
  20. function (error) {
  21. if (error) {
  22. console.log(error)
  23. } else {
  24. console.log('DONE 👌')
  25. }
  26. process.exit()
  27. }
  28. )
  29. }
  30. try {
  31. await waitForDb()
  32. await main()
  33. } catch (error) {
  34. console.error(error)
  35. process.exit(1)
  36. }