<commit_before>'use strict';

const uuid = require('uuid');
const defaults = require('./defaults');
const utils = require('./utils');
const error = require('http-errors');

const TABLE = 'expenses';
const FIELDS = ['id', 'item', 'amount', 'date', 'created_at', 'updated_at'];

const validate = (expense) => {
  if (!expense.item || typeof expense.item !== 'string') {
    return error.BadRequest('Item must be a string');
  }
  if (isNaN(expense.amount) || expense.amount === Infinity) {
    return error.BadRequest('Amount must be a number');
  }
  if (expense.amount < 0) {
    return error.BadRequest('Amount must be a positive number');
  }
}

const store = module.exports = (db) => {

  const store = {};

  /**
   * Find all expenses from database, optionally accepts a pager object and additional filter
   * options.
   */
  store.findAll = (options) => {
    options = options || {};

    const pager = options.pager || {page: 1, pageSize: defaults.PAGE_SIZE};
    const offset = (pager.page-1)*pager.pageSize;

    const query = db
      .table(TABLE)
      .select(FIELDS)
      .limit(pager.pageSize)<commit_msg>Make store inherit defaults via prototype<commit_after>'use strict';

const uuid = require('uuid');
const defaults = require('./defaults');
const utils = require('./utils');
const error = require('http-errors');

const TABLE = 'expenses';
const FIELDS = ['id', 'item', 'amount', 'date', 'created_at', 'updated_at'];

const validate = (expense) => {
  if (!expense.item || typeof expense.item !== 'string') {
    return error.BadRequest('Item must be a string');
  }
  if (isNaN(expense.amount) || expense.amount === Infinity) {
    return error.BadRequest('Amount must be a number');
  }
  if (expense.amount < 0) {
    return error.BadRequest('Amount must be a positive number');
  }
}

const store = module.exports = (db) => {

  // Create new object to hold exported properties, inherit default props
  const store = Object.create(defaults);

  /**
   * Find all expenses from database, optionally accepts a pager object and additional filter
   * options.
   */
  store.findAll = (options) => {
    options = options || {};

    const pager = options.pager || {page: 1, pageSize: defaults.PAGE_SIZE};
    const offset = (pager.page-1)*pager.pageSize;

    const query = db
      .table(TABLE)
      .select(FIELDS)
      .limit(pager.pageSize)
{'fraction_non_alphanumeric': 0.1552087726697596, 'fraction_numerical': 0.0025305778152678194, 'mean_word_length': 3.5968992248062017, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '1657113', 'n_tokens_mistral': 728, 'n_tokens_neox': 715, 'n_words': 213}