12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. var ip = require('ip');
  2. var Tool = require('../models/Tool');
  3. var logger = require('../utils/logger');
  4. var validation = require('../validation');
  5. /* CREATE (GUARDED) */
  6. /* READ (UNGUARDED) */
  7. /**
  8. * Function for getting all the tools from the DB.
  9. * @param req The request object sent over from the route.
  10. * @param res The response object sent over from the route.
  11. */
  12. exports.getTools = function (req, res) {
  13. //Find all tools
  14. Tool.find({}, function (err, tools) {
  15. if (err)
  16. res.status(404).send({message: "Could not retrieve Tools.", errors: err});
  17. else
  18. res.status(200).send(tools);
  19. });
  20. };
  21. /**
  22. * Function for getting info for all the tools (ids and names)
  23. * @param req The request object sent over from the route.
  24. * @param res The response object sent over from the route.
  25. */
  26. exports.getToolInfo = function (req, res) {
  27. //Find all tools, only returning the id and name for each
  28. Tool.find({}, {_id: false, id: true, name: true}, function (err, tools) {
  29. if (err)
  30. res.status(404).send({message: "Could not retrieve Tools.", errors: err});
  31. else
  32. res.status(200).send(tools);
  33. });
  34. };
  35. /**
  36. * Function for getting all the tool names
  37. * @param req The request object sent over from the route.
  38. * @param res The response object sent over from the route.
  39. */
  40. exports.getToolNames = function (req, res) {
  41. //Find all tools, only returning the name
  42. Tool.find({}, {_id: false, name: true}, function (err, tools) {
  43. var toolsMap = [];
  44. tools.forEach(function (tool) {
  45. toolsMap.push(tool.name);
  46. });
  47. if (err)
  48. res.status(404).send({message: "Could not retrieve Tools.", errors: err});
  49. else
  50. res.status(200).send(toolsMap);
  51. });
  52. };
  53. /**
  54. * Function for getting all the tool ids
  55. * @param req The request object sent over from the route.
  56. * @param res The response object sent over from the route.
  57. */
  58. exports.getToolIds = function (req, res) {
  59. //Find all the tools, only returning the id
  60. Tool.find({}, {_id: false, id: true}, function (err, tools) {
  61. var toolsMap = [];
  62. tools.forEach(function (tool) {
  63. toolsMap.push(tool.id);
  64. });
  65. if (err)
  66. res.status(404).send({message: "Could not retrieve Tools.", errors: err});
  67. else
  68. res.status(200).send(toolsMap);
  69. });
  70. };
  71. /* UPDATE (GUARDED) */
  72. /* DELETE (GUARDED) */