refresh_institution_users.js 1.0 KB

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