punishments.js 855 B

123456789101112131415161718192021222324252627282930313233
  1. 'use strict';
  2. const hooks = require('./hooks'),
  3. async = require('async'),
  4. logger = require('../logger'),
  5. utils = require('../utils'),
  6. db = require('../db');
  7. module.exports = {
  8. /**
  9. * Gets all punishments
  10. *
  11. * @param {Object} session - the session object automatically added by socket.io
  12. * @param {Function} cb - gets called with the result
  13. */
  14. index: hooks.adminRequired((session, cb) => {
  15. async.waterfall([
  16. (next) => {
  17. db.models.punishment.find({}, next);
  18. }
  19. ], (err, punishments) => {
  20. if (err) {
  21. err = utils.getError(err);
  22. logger.error("PUNISHMENTS_INDEX", `Indexing punishments failed. "${err}"`);
  23. return cb({ 'status': 'failure', 'message': err});
  24. }
  25. logger.success("PUNISHMENTS_INDEX", "Indexing punishments successful.");
  26. cb({ status: 'success', data: punishments });
  27. });
  28. }),
  29. };