refresh_institution_users.mjs 980 B

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