<commit_before>/*
 * mik-loan
 * https://github.com/ellnestam/mik-loan
 *
 * Copyright (c) 2013 <NAME>
 * Licensed under the MIT license.
 */

'use strict';

var url = require('url');
var http = require('http');
var repository = require('./loan/repository.js');

var APPLICATION = "apply";
var FETCH = "fetch";
var TICKET_ID = "ticketId";
var APPROVE = "approve";

var srv = http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'application/json'});
    var url_parts = url.parse(req.url, true);
    var query = url_parts.query;

    if (query.action === 'apply') {
	var application = {amount: query['amount'],
			   contact: query['contact'],
			   applicationNo: 3 
			  };
	repository.store(application, function printTicket(ticket) {
	    res.end(ticket + '\n');
	});

    } else if (query.action === 'fetch') {
	var ticketId = query[TICKET_ID];
        repository.fetch(ticketId, function printFetched(data) {
	    console.log('D2: ' + data);
	    res.end(data + '\n');
	});
	return;
    } else if (query.action === 'approve') {
        repository.approveLoan(query[TICKET_ID], function printTicket(ticket) {
	    res.end(ticket + '\n');
	});
	return;
    }

    res.end('Incorrect parameters provided\n');
}).listen(8080);

function approveLoan(ticketId) {
    return 'Approving ' + ticketId + '\n';;
};

function fetchLoanInfo(ticketId) {
    return JSON.stringify(repository.fetch(ticketId)) + '\n';
}

/* console.log('Storing that mutha');
var files = fs.readdir('loans', function(err, list) {
    console.log(list);
    
});
console.log(files); */


<commit_msg>Clean up<commit_after>'use strict';

var url = require('url');
var http = require('http');
var repository = require('./loan/repository.js');

var APPLICATION = "apply";
var FETCH = "fetch";
var TICKET_ID = "ticketId";
var APPROVE = "approve";

var srv = http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'application/json'});
    var url_parts = url.parse(req.url, true);
    var query = url_parts.query;

    if (query.action === 'apply') {
	var application = {amount: query['amount'],
			   contact: query['contact'],
			   applicationNo: 3 
			  };
	repository.store(application, function printTicket(ticket) {
	    res.end(ticket + '\n');
	});

    } else if (query.action === 'fetch') {
	var ticketId = query[TICKET_ID];
        repository.fetch(ticketId, function printFetched(application) {
	    res.end(application + '\n');
	});
	return;
    } else if (query.action === 'approve') {
        repository.approveLoan(query[TICKET_ID], function printTicket(ticket) {
	    res.end(ticket + '\n');
	});
	return;
    }

    res.end('Incorrect parameters provided\n');
}).listen(8080);
{'fraction_non_alphanumeric': 0.1761238025055269, 'fraction_numerical': 0.007737656595431098, 'mean_word_length': 3.6810344827586206, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 1, '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': '5647656', 'n_tokens_mistral': 973, 'n_tokens_neox': 900, 'n_words': 198}