audit-log.js 962 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. Model.knex(db);
  7. class AuditLog extends Model {
  8. $beforeInsert () {
  9. this.created_on = Model.raw('NOW()');
  10. this.modified_on = Model.raw('NOW()');
  11. // Default for meta
  12. if (typeof this.meta === 'undefined') {
  13. this.meta = {};
  14. }
  15. }
  16. $beforeUpdate () {
  17. this.modified_on = Model.raw('NOW()');
  18. }
  19. static get name () {
  20. return 'AuditLog';
  21. }
  22. static get tableName () {
  23. return 'audit_log';
  24. }
  25. static get jsonAttributes () {
  26. return ['meta'];
  27. }
  28. static get relationMappings () {
  29. return {
  30. user: {
  31. relation: Model.HasOneRelation,
  32. modelClass: User,
  33. join: {
  34. from: 'audit_log.user_id',
  35. to: 'user.id'
  36. },
  37. modify: function (qb) {
  38. qb.omit(['id', 'created_on', 'modified_on', 'roles']);
  39. }
  40. }
  41. };
  42. }
  43. }
  44. module.exports = AuditLog;