{"size": 662, "ext": "js", "max_stars_repo_path": "src/apps/chat/models/subscription.js", "max_stars_repo_name": "ccetc/mahaplatform.com", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/apps/chat/models/subscription.js", "max_issues_repo_name": "ccetc/mahaplatform.com", "max_issues_repo_issues_event_min_datetime": "2019-10-28T15:38:35.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-28T04:23:48.000Z", "max_forks_repo_path": "src/apps/chat/models/subscription.js", "max_forks_repo_name": "mahaplatform/mahaplatform.com", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 52, "max_forks_count": null, "avg_line_length": 18.9142857143, "max_line_length": 67, "alphanum_fraction": 0.6616314199}
import knex from '@core/vendor/knex/maha'
import Model from '@core/objects/model'
import User from '@apps/maha/models/user'
import Channel from './channel'
import Message from './message'

const Subscription = new Model(knex, {

  databaseName: 'maha',

  tableName: 'chat_subscriptions',

  rules: {
    channel_id: ['required'],
    user_id: ['required']
  },

  channel() {
    return this.belongsTo(Channel, 'channel_id')
  },

  last_message() {
    return this.belongsTo(Message, 'last_message_id').query(qb => {
      qb.where({ message_type_id: 2 })
    })
  },

  user() {
    return this.belongsTo(User, 'user_id')
  }

})

export default Subscription
