<commit_before>export const config = {
  key: 'referendumId'
};

export function handler(referendumList, eventData) {
  const event = eventData.event;
  switch(eventData.typeId) {
    case 'ReferendumCreated':
      var referendumRecordIndex = referendumList.findIndex(isInListAlready, eventData.event.referendumId);
      if(referendumRecordIndex === -1) {
        referendumList.push({
          referendumId: event.referendumId,
          organizationId: event.organizationId,
          name: event.name,
          proposal: event.proposal,
          options: event.options, 
        });
      }
      break;
    case 'VoteCast':
      var referendumRecordIndex = referendumList.findIndex(isInListAlready, eventData.event.referendumId);
      if(referendumRecordIndex === -1) {
        throw new Error("Referendum " + event.referendumId + ": Referendum with referendumId " + event.referendumId + " not found.");
      }
      let referendum = referendumList[referendumRecordIndex];
      let currentTallyForOption = referendum.options[event.vote];
      referendum.options[event.vote] = currentTallyForOption + 1;
      referendumList = [
        ...referendumList.slice(0, referendumRecordIndex),
        referendum,
        ...referendumList.slice(referendumRecordIndex+1)
      ]
      break;
  }
  return referendumList;
}

function isInListAlready(referendum) {
    return referendum.referendumId === this;
}<commit_msg>Infrastructure upgrade - referendum list read model<commit_after>export const config = {
  key: 'referendumId'
};

export function handler(referendumList, eventData) {
  const event = eventData.event;
  switch(eventData.typeId) {
    case 'ReferendumCreated':
        referendumList.create({
          referendumId: event.referendumId,
          organizationId: event.organizationId,
          name: event.name,
          proposal: event.proposal,
          options: event.options, 
        });
      break;
  }
  return referendumList;
}
{'fraction_non_alphanumeric': 0.10020345879959308, 'fraction_numerical': 0.00254323499491353, 'mean_word_length': 3.0893970893970892, 'pattern_counts': {'":': 1, '<': 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': '3690970', 'n_tokens_mistral': 607, 'n_tokens_neox': 570, 'n_words': 107}