<commit_before>import { EventActions } from './EventActions'
import { Event, User, Permission } from '../models'
import { rejectIfNull } from './util'
import * as mongodb from '../mongodb/Event'

export class EventActionsImpl implements EventActions {

  getEvents(auth: User): Promise<Event[]> {
    if (auth) {
      // All fields
      return mongodb.Event.find().exec()
    } else {
      // Public event
      return mongodb.Event.find({}, {
        'id': true,
        'companyName': true,
        'publicDescription': true,
        'date': true,
        'pictures': true,
      }).exec()
    }
  }

  createEvent(auth: User, companyName: string, fields: Partial<Event>):
    Promise<Event> {
    if (!auth.permissions.includes(Permission.Events))
      return Promise.reject('Insufficient permissions')
    const event = new mongodb.Event({
      companyName,
      ...fields,
    })
    return event.save()
  }

  updateEvent(auth: User, id: string, fields: Partial<Event>): Promise<Event> {
    if (!auth.permissions.includes(Permission.Events))
      return Promise.reject('Insufficient permissions')
    return mongodb.Event.findOneAndUpdate(<commit_msg>HOTFIX: Make 'published' a public field on events<commit_after>import { EventActions } from './EventActions'
import { Event, User, Permission } from '../models'
import { rejectIfNull } from './util'
import * as mongodb from '../mongodb/Event'

export class EventActionsImpl implements EventActions {

  getEvents(auth: User): Promise<Event[]> {
    if (auth) {
      // All fields
      return mongodb.Event.find().exec()
    } else {
      // Public event
      return mongodb.Event.find({}, {
        'id': true,
        'companyName': true,
        'publicDescription': true,
        'date': true,
        'pictures': true,
        'published': true,
      }).exec()
    }
  }

  createEvent(auth: User, companyName: string, fields: Partial<Event>):
    Promise<Event> {
    if (!auth.permissions.includes(Permission.Events))
      return Promise.reject('Insufficient permissions')
    const event = new mongodb.Event({
      companyName,
      ...fields,
    })
    return event.save()
  }

  updateEvent(auth: User, id: string, fields: Partial<Event>): Promise<Event> {
    if (!auth.permissions.includes(Permission.Events))
      return Promise.reject('Insufficient permissions')
    return mongodb.Event.findOneAndUpdate(
{'fraction_non_alphanumeric': 0.1374843292937735, 'fraction_numerical': 0.0, 'mean_word_length': 3.0303030303030303, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '1194584', 'n_tokens_mistral': 698, 'n_tokens_neox': 674, 'n_words': 174}