<commit_before>import Realm from 'realm';
import { getTotal } from '../utilities';

export class Item extends Realm.Object {
  get totalQuantity() {
    return getTotal(this.batches, 'totalQuantity');
  }

  get dailyUsage() {
    return getTotal(this.batches, 'dailyUsage');
  }

  get earliestExpiryDate() {
    if (this.batches.length === 0) return null;
    return this.batches.reduce((earliest, batch) => {
      if (batch.totalQuantity !== 0 && earliest < batch.expiryDate) return earliest;
      return batch.expiryDate;
    }, this.batches[0]);
  }

  addBatch(itemBatch) {
    // If the batch is already in the item, we don't want to add it again
    if (this.batches.find(currentItemBatch => currentItemBatch.id === itemBatch.id)) return;
    this.batches.push(itemBatch);
  }

  toString() {
    return `${this.code} - ${this.name}`;
  }
}<commit_msg>Actually added the item.categoryName function, and departmentName<commit_after>import Realm from 'realm';
import { getTotal } from '../utilities';

export class Item extends Realm.Object {
  get totalQuantity() {
    return getTotal(this.batches, 'totalQuantity');
  }

  get dailyUsage() {
    return getTotal(this.batches, 'dailyUsage');
  }

  get earliestExpiryDate() {
    if (this.batches.length === 0) return null;
    return this.batches.reduce((earliest, batch) => {
      if (batch.totalQuantity !== 0 && earliest < batch.expiryDate) return earliest;
      return batch.expiryDate;
    }, this.batches[0]);
  }

  get categoryName() {
    return this.category ? this.category.name : '';
  }

  get departmentName() {
    return this.department ? this.department.name : '';
  }


  addBatch(itemBatch) {
    // If the batch is already in the item, we don't want to add it again
    if (this.batches.find(currentItemBatch => currentItemBatch.id === itemBatch.id)) return;
    this.batches.push(itemBatch);
  }

  toString() {
    return `${this.code} - ${this.name}`;
  }
}
{'fraction_non_alphanumeric': 0.1399897066392177, 'fraction_numerical': 0.003088008234688626, 'mean_word_length': 3.4689655172413794, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '2338380', 'n_tokens_mistral': 638, 'n_tokens_neox': 608, 'n_words': 154}