audit-log.js 867 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Objection Docs:
  2. // http://vincit.github.io/objection.js/
  3. const db = require('../db');
  4. const Model = require('objection').Model;
  5. const User = require('./user');
  6. const now = require('./now_helper');
  7. Model.knex(db);
  8. class AuditLog extends Model {
  9. $beforeInsert () {
  10. this.created_on = now();
  11. this.modified_on = now();
  12. // Default for meta
  13. if (typeof this.meta === 'undefined') {
  14. this.meta = {};
  15. }
  16. }
  17. $beforeUpdate () {
  18. this.modified_on = now();
  19. }
  20. static get name () {
  21. return 'AuditLog';
  22. }
  23. static get tableName () {
  24. return 'audit_log';
  25. }
  26. static get jsonAttributes () {
  27. return ['meta'];
  28. }
  29. static get relationMappings () {
  30. return {
  31. user: {
  32. relation: Model.HasOneRelation,
  33. modelClass: User,
  34. join: {
  35. from: 'audit_log.user_id',
  36. to: 'user.id'
  37. }
  38. }
  39. };
  40. }
  41. }
  42. module.exports = AuditLog;