refresh_institution_users.mjs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import minimist from 'minimist'
  2. import InstitutionsManager from '../app/src/Features/Institutions/InstitutionsManager.js'
  3. import { scriptRunner } from './lib/ScriptRunner.mjs'
  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 scriptRunner(main)
  32. } catch (error) {
  33. console.error(error)
  34. process.exit(1)
  35. }