<commit_before>import mongoose from 'mongoose';
import Boom from 'boom';
import Bounce from 'bounce';
import { logErr } from '../../shared/utils';
import eventStore from '../stores/eventStore';
import userStore from '../stores/userStore';

const ObjectId = mongoose.Types.ObjectId;

const eventController = {
  async createEvent(req, h) {
    let data;
    try {
      data = req.payload;
      // Fetch user id from username and add to created.by.user
      const user = await userStore.getUserByPhoneOrEmail(data.user.username);
      data["created.by.user"] = user._id;
      const event = await eventStore.createEvent(data);
      if (!event) throw new Error("Event returned empty.");
      const response = h.response(event);
      return response;
    } catch (err) {
      if (Bounce.isSystem(err)) logErr("eventController createEvent error: ", err.message || err);
      return Boom.badRequest(err.message || "Error creating event.");<commit_msg>Event POST: Delete extraneous info from update data<commit_after>import mongoose from 'mongoose';
import Boom from 'boom';
import Bounce from 'bounce';
import { logErr } from '../../shared/utils';
import eventStore from '../stores/eventStore';
import userStore from '../stores/userStore';

const ObjectId = mongoose.Types.ObjectId;

const eventController = {
  async createEvent(req, h) {
    let data;
    try {
      data = req.payload;
      // Fetch user id from username and add to created.by.user
      const user = await userStore.getUserByPhoneOrEmail(data.user.username);
      delete data["user"];
      data["created.by.user"] = user._id;
      const event = await eventStore.createEvent(data);
      if (!event) throw new Error("Event returned empty.");
      const response = h.response(event);
      return response;
    } catch (err) {
      if (Bounce.isSystem(err)) logErr("eventController createEvent error: ", err.message || err);
      return Boom.badRequest(err.message || "Error creating event.");
{'fraction_non_alphanumeric': 0.12671059300557527, 'fraction_numerical': 0.0, 'mean_word_length': 3.506849315068493, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5622342', 'n_tokens_mistral': 560, 'n_tokens_neox': 566, 'n_words': 172}