 
 
 Meteor.methods
-  addIncidentReport: (incident) ->
+  addIncidentReport: (incident, updateEvent=true) ->
     incidentReportSchema.validate(incident)
     user = Meteor.user()
     if not Roles.userIsInRole(user._id, ['admin'])

        incidents.push(incident)
        if addToCollection
          _incident = _.pick(incident, incidentReportSchema.objectKeys())
          Meteor.call('addIncidentReport', _incident)

      content: enhancements.source.cleanContent.content
      incidents: incidents

    incident.addedByUserName = user.profile.name
    incident.addedDate = new Date()
    newId = Incidents.insert(incident)
    if updateEvent
      Meteor.call("editUserEventLastModified", incident.userEventId)
      Meteor.call("editUserEventLastIncidentDate", incident.userEventId)
    return newId

  editIncidentReport: (incident, updateEvent=true) ->
    incidentReportSchema.validate(incident)
    user = Meteor.user()
    if not Roles.userIsInRole(user._id, ['admin'])
      throw new Meteor.Error("auth", "User does not have permission to edit incident reports")
    res = Incidents.update(incident._id, incident)
    if updateEvent
      Meteor.call("editUserEventLastModified", incident.userEventId)
      Meteor.call("editUserEventLastIncidentDate", incident.userEventId)
    return incident._id

  addIncidentReports: (incidents, updateEvents=true) ->
    incidents.map (incident)->
      Meteor.call("addIncidentReport", incident, updateEvents)

  removeIncidentReport: (id, updateEvent) ->
    if not Roles.userIsInRole(@userId, ['admin'])
      throw new Meteor.Error("auth", "User does not have permission to edit incident reports")
    incident = Incidents.findOne(id)
