audit-log.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. const express = require('express');
  2. const validator = require('../lib/validator');
  3. const jwtdecode = require('../lib/express/jwt-decode');
  4. const internalAuditLog = require('../internal/audit-log');
  5. let router = express.Router({
  6. caseSensitive: true,
  7. strict: true,
  8. mergeParams: true
  9. });
  10. /**
  11. * /api/audit-log
  12. */
  13. router
  14. .route('/')
  15. .options((_, res) => {
  16. res.sendStatus(204);
  17. })
  18. .all(jwtdecode())
  19. /**
  20. * GET /api/audit-log
  21. *
  22. * Retrieve all logs
  23. */
  24. .get((req, res, next) => {
  25. validator({
  26. additionalProperties: false,
  27. properties: {
  28. expand: {
  29. $ref: 'common#/definitions/expand'
  30. },
  31. query: {
  32. $ref: 'common#/definitions/query'
  33. }
  34. }
  35. }, {
  36. expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null),
  37. query: (typeof req.query.query === 'string' ? req.query.query : null)
  38. })
  39. .then((data) => {
  40. return internalAuditLog.getAll(res.locals.access, data.expand, data.query);
  41. })
  42. .then((rows) => {
  43. res.status(200)
  44. .send(rows);
  45. })
  46. .catch(next);
  47. });
  48. module.exports = router;