access_list_client.js 1.1 KB

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