access_list_client.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Objection Docs:
  2. // http://vincit.github.io/objection.js/
  3. const db = require('../db');
  4. const Model = require('objection').Model;
  5. const now = require('./now_helper');
  6. Model.knex(db);
  7. class AccessListClient extends Model {
  8. $beforeInsert () {
  9. this.created_on = now();
  10. this.modified_on = now();
  11. // Default for meta
  12. if (typeof this.meta === 'undefined') {
  13. this.meta = {};
  14. }
  15. }
  16. $beforeUpdate () {
  17. this.modified_on = now();
  18. }
  19. static get name () {
  20. return 'AccessListClient';
  21. }
  22. static get tableName () {
  23. return 'access_list_client';
  24. }
  25. static get jsonAttributes () {
  26. return ['meta'];
  27. }
  28. static get relationMappings () {
  29. return {
  30. access_list: {
  31. relation: Model.HasOneRelation,
  32. modelClass: require('./access_list'),
  33. join: {
  34. from: 'access_list_client.access_list_id',
  35. to: 'access_list.id'
  36. },
  37. modify: function (qb) {
  38. qb.where('access_list.is_deleted', 0);
  39. qb.omit(['created_on', 'modified_on', 'is_deleted', 'access_list_id']);
  40. }
  41. }
  42. };
  43. }
  44. get rule() {
  45. return `${this.directive} ${this.address}`;
  46. }
  47. }
  48. module.exports = AccessListClient;