{"size": 972, "ext": "js", "max_stars_repo_path": "api/models/Stream.js", "max_stars_repo_name": "dadleyy/loftili.api", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "api/models/Stream.js", "max_issues_repo_name": "dadleyy/loftili.api", "max_issues_repo_issues_event_min_datetime": "2019-07-23T19:24:29.000Z", "max_issues_repo_issues_event_max_datetime": "2019-07-23T19:24:29.000Z", "max_forks_repo_path": "api/models/Stream.js", "max_forks_repo_name": "dadleyy/loftili.api", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 17.3571428571, "max_line_length": 65, "alphanum_fraction": 0.5637860082}
module.exports = (function() {

  var Stream = {};

  Stream.writable = [
    "title", "description", "privacy"
  ];

  Stream.attributes = {

    title: {
      type: "string",
      required: true
    },

    description: {
      type: "string",
      required: true
    },

    /* stream privacy:
     * 0: anyone can subscribe, anyone can conribute
     * 1: anyone can subscribe, contributors can contribute
     * 2: contributors only
     */
    privacy: {
      type: "integer",
      required: true,
      defaultsTo: 0
    },

    permissions: {
      collection: "StreamPermission",
      via: "stream"
    }

  };

  Stream.beforeDestroy = function(criteria, cb) {
    var id = criteria.where.id;

    function destroyPermissions(err, permissions) {
      for(var i = 0; i < permissions.length; i++) {
        permissions[i].destroy();
      }
      cb();
    }

    StreamPermission.find({stream: id}).exec(destroyPermissions);
  };

  return Stream;


})();
