<commit_before>'use strict'

const MongoClient = require('mongodb').MongoClient;
const ObjectId = require('mongodb').ObjectID;

module.exports = (mongodbUrl) => {

  async function getQuestionnaires() {
    // TODO: Mongodb-kutsu
    return new Promise(function(resolve, reject){
      setTimeout(function(){
        resolve("Hello World");
      }, 1000)
    });
  }
  async function putQuestionnaire(payload) {
    return new Promise(function(resolve, reject){
      let insertQuestionnaire = function(db, callback) {
        db.collection('questionnaires').insertOne(payload, function(err, result) {
          console.log("Inserted a questionnaire into the questionnaires collection.");
          callback();
        });
      };
      MongoClient.connect(mongodbUrl, function(err, db) {
        insertQuestionnaire(db, function() {
          db.close();
        });
      });
      
      let returnJson = new Object();
      returnJson.uuid = payload.uuid;
      returnJson.created = payload.created;
      returnJson.modified = payload.modified;
      resolve(JSON.stringify(returnJson));
    });
  }

  return {
    getQuestionnaires: getQuestionnaires,
    putQuestionnaire: putQuestionnaire
  };
}<commit_msg>Add getQuestionnaires functionality, Fix putQuestionnaire<commit_after>'use strict'

const MongoClient = require('mongodb').MongoClient;
const ObjectId = require('mongodb').ObjectID;

module.exports = (mongodbUrl) => {

  async function getQuestionnaires() {
    // TODO: Mongodb-kutsu
    return new Promise(function(resolve, reject){
      let findQuestionnaires = function(db, callback) {
      	let resultsArray = new Array();
        let cursor = db.collection('questionnaires').find( );
        cursor.each(function(err, doc) {
          if (doc !== null) {
          	 resultsArray.push(doc);
          } else {
            callback(resultsArray);
          }
        });
      };
      MongoClient.connect(mongodbUrl, function(err, db) {
        findQuestionnaires(db, function(resultsArray) {
          db.close();
          resolve(JSON.stringify(resultsArray));
        });
      });
    });
  }
  
  async function putQuestionnaire(payload) {
    return new Promise(function(resolve, reject){
      let insertQuestionnaire = function(db, callback) {
        db.collection('questionnaires').insertOne(payload, function(err, result) {
          console.log("Inserted a questionnaire into the questionnaires collection.");
          callback();
        });
      };
      MongoClient.connect(mongodbUrl, function(err, db) {
        insertQuestionnaire(db, function() {
          db.close();
          
          let returnJson = new Object();
          returnJson.uuid = payload.uuid;
          returnJson.created = payload.created;
          returnJson.modified = payload.modified;
          resolve(JSON.stringify(returnJson));
        });
      });
    });
  }

  return {
    getQuestionnaires: getQuestionnaires,
    putQuestionnaire: putQuestionnaire
  };
}
{'fraction_non_alphanumeric': 0.12073578595317726, 'fraction_numerical': 0.0013377926421404682, 'mean_word_length': 2.720149253731343, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '698358', 'n_tokens_mistral': 825, 'n_tokens_neox': 797, 'n_words': 160}