<commit_before>'use strict';

var AWS = require("aws-sdk");
var mysql = require('mysql');

const mock_payload = [
  {
    "address": "123 Main Street",
    "mls_number": "55454454",
    "agent_first_name": "Jane",
    "agent_last_name": "Doe",
    "agent_brokerage": "XYZ Brokerage",
    "agent_designations": "CPRS, e-Pro",
    "": "",
    "": "",
    "": "",
    "": "",
  },
  {
    "address": "456 Elm Street",
    "mls_number": "098767890",
    "agent_first_name": "Jane",
    "agent_last_name": "Doe",
    "agent_brokerage": "XYZ Brokerage",
    "agent_designations": "CPRS, e-Pro",
    "": "",
    "": "",
    "": "",
    "": "",
  },
  {
    "address": "122 Andrews Ave",
    "mls_number": "2465422332",
    "agent_first_name": "Jane",
    "agent_last_name": "Doe",
    "agent_brokerage": "XYZ Brokerage",
    "agent_designations": "CPRS, e-Pro",
    "": "",
    "": "",
    "": "",
    "": "",
  }
]


/*
    Return offer search results that meet the specified criteria
*/
exports.handler = (event, context, callback) => {
    console.log('Received event:', JSON.stringify(event, null, 2));
    queryDatabase();
    callback(null, mock_payload);

};

function queryDatabase() {
    var connection = mysql.createConnection({
          host     : 'chqgb39str0o.us-west-1.rds.amazonaws.com:3306',
          user     : '<myusername>',
          password : '<<PASSWORD>>',
          database : 'tracker'
    });
    connection.connect(function(err){
          if(!err) {
                console.log("Database is connected ... nn");
          }
          else {
                console.log("Error connecting database ... nn");
          }
    });

    connection.query("INSERT INTO Users (user_id) VALUES ('TESTNAME')");
    connection.end();
};<commit_msg>Working offers-search function<commit_after>'use strict';

var AWS = require("aws-sdk");
var mysql = require('mysql');

exports.handler = (event, context, callback) => {
    console.log("Querying database...");
    var result = queryDatabase(function(result) {
        console.log("about to return result 2:");
        console.log(result);
        callback(null, result);
    });
};

function queryDatabase(callback) {
    var connection = mysql.createConnection({
          host     : 'tracker.chqgb39str0o.us-west-1.rds.amazonaws.com',
          user     : 'tracker',
          password : '<PASSWORD>',
          database : 'tracker'
    });

    connection.connect(function(err){
          if(!err) {
                console.log("Database is connected");
                connection.query(`
                  select
                  	offers.address,
                      offers .mls_number,
                      agents.first_name "agent_first_name",
                      agents.last_name "agent_last_name",
                      agents.brokerage "agent_brokerage",
                      agents.designations "agent_designations"
                  from
                  	offers
                      join agent_offer on offers.id = agent_offer.offer_id
                      join agents on agent_offer.agent_id = agents.id
                  `, function (err, result, fields) {
                    connection.end();
                    if (err) {
                        console.log("An error occured:");
                        console.log(err);
                    };
                    console.log("about to return result 1:");
                    console.log(result);
                    callback(result);
                  })
          }
          else {
                console.log("Error connecting database ... nn");
                console.log(err);
          }
    });

};
{'fraction_non_alphanumeric': 0.1491636961886482, 'fraction_numerical': 0.013984096517685769, 'mean_word_length': 1.8148148148148149, 'pattern_counts': {'":': 30, '<': 7, '<?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': '3484353', 'n_tokens_mistral': 1107, 'n_tokens_neox': 1043, 'n_words': 204}