<commit_before>var _ = require('underscore');
var util = require('util');
var db = require('mongoskin').db('mongodb://localhost:27017/shop')

function ShoppingList() {}

// Get names of all lists available
ShoppingList.prototype.all = function(resolve) {
  db.collection("shoppingLists").find().toArray(function(err, result) {
    resolve(
      _.map(result, function(x) { return x["name"]; })
    );
  });
};

// Create a named list
ShoppingList.prototype.create = function(listName, resolve) {
  // @TODO: check that the list name is unique
  db.collection("shoppingLists").insert({ name: listName, items: [] }, function(err, result) {
    resolve(result);
  });
};

// Get specific named list
ShoppingList.prototype.find = function(listName, resolve) {
  db.collection("shoppingLists").findOne( { name: listName }, function(err, result) {
    resolve(result);
  });
};

// Add items to a list
ShoppingList.prototype.addItems = function(listName, listItems, resolve) {
  db.collection("shoppingLists").update(
    { name: listName },
    { $push: { items:  { $each: listItems } } },
    function(err, result) {
      resolve(result);
    }
  );
};

// Delete items from a list
ShoppingList.prototype.deleteItems = function(listName, idsToDelete, resolve) {
  console.log("deleting items from ");
  console.log(listName);
  console.log("with ids in ");
  console.log(idsToDelete);
  db.collection("shoppingLists").update(
    { name: listName },
    { $pull: { items:  { _id: { $in: idsToDelete } } } },
    function(err, result) {
      resolve(result);
    }
  );
};

module.exports = new ShoppingList();<commit_msg>Return the updated list after updates<commit_after>var _ = require('underscore');
var util = require('util');
var db = require('mongoskin').db('mongodb://localhost:27017/shop')

function ShoppingList() {}

// Get names of all lists available
ShoppingList.prototype.all = function(resolve) {
  db.collection("shoppingLists").find().toArray(function(err, result) {
    resolve(
      _.map(result, function(x) { return x["name"]; })
    );
  });
};

// Create a named list
ShoppingList.prototype.create = function(listName, resolve) {
  // @TODO: check that the list name is unique
  db.collection("shoppingLists").insert({ name: listName, items: [] }, function(err, result) {
    resolve(result);
  });
};

// Get specific named list
ShoppingList.prototype.find = function(listName, resolve) {
  db.collection("shoppingLists").findOne( { name: listName }, function(err, result) {
    resolve(result);
  });
};

// Add items to a list
ShoppingList.prototype.addItems = function(listName, listItems, resolve) {
  db.collection("shoppingLists").update(
    { name: listName },
    { $push: { items:  { $each: listItems } } },
    function(err, result) {
      if (err) throw err;
    }
  );

  // Return the updated list
  db.collection("shoppingLists").findOne( { name: listName }, function(err, result) {
    resolve(result);
  });
};

// Delete items from a list
ShoppingList.prototype.deleteItems = function(listName, idsToDelete, resolve) {
  db.collection("shoppingLists").update(
    { name: listName },
    { $pull: { items:  { _id: { $in: idsToDelete } } } },
    function(err, result) {
      if (err) throw err;
    }
  );

  // Return the updated list
  db.collection("shoppingLists").findOne( { name: listName }, function(err, result) {
    resolve(result);
  });
};

module.exports = new ShoppingList();
{'fraction_non_alphanumeric': 0.16312263326536558, 'fraction_numerical': 0.0029129041654529565, 'mean_word_length': 3.9339080459770117, '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': '6516581', 'n_tokens_mistral': 1095, 'n_tokens_neox': 1082, 'n_words': 242}