<commit_before>_ = require('lodash')

defineProperties = require('utils/define-properties')

### @ngInject ###
module.exports = (RoundModel) ->
  class GroupModel
    constructor: (data = {}) ->
      @id = data.id
      @name = data.name
      @rounds = _.map data.rounds, (round) ->
        new RoundModel(round)

      defineProperties @,
        members:
          deps: ['memberships']
          get: ->
            _.pluck @memberships, 'user'

    isAdmin: (user) ->
      if typeof @memberships == 'undefined'
        throw new Error("""
          Unable to check if user #{user.id}
          is admin of group #{@id}, do not
          have access to memberships
        """)

      membership = _.find @memberships, (m) ->
        m.user.id == user.id

      membership and membership.isAdmin<commit_msg>clean up isAdmin code<commit_after>_ = require('lodash')

defineProperties = require('utils/define-properties')

### @ngInject ###
module.exports = (RoundModel) ->
  class GroupModel
    constructor: (data = {}) ->
      @id = data.id
      @name = data.name
      @rounds = _.map data.rounds, (round) ->
        new RoundModel(round)

      defineProperties @,
        members:
          deps: ['memberships']
          get: ->
            _.pluck @memberships, 'user'

    getMembership: (user) ->
      if typeof @memberships == 'undefined'
        throw new Error("""
          Unable to find user #{user.id}
          membership in group #{@id}, do not
          have access to memberships
        """)

      _.find @memberships, (m) ->
        m.user.id == user.id

    isAdmin: (user) ->
      membership = @getMembership(user)
      membership and membership.isAdmin
{'fraction_non_alphanumeric': 0.13507109004739337, 'fraction_numerical': 0.0, 'mean_word_length': 2.0990825688073396, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3306386', 'n_tokens_mistral': 504, 'n_tokens_neox': 490, 'n_words': 131}