Commit ef6b2664 authored by Marius Wybrands's avatar Marius Wybrands

csv parser implemented

parent 3caadb3e
......@@ -8,8 +8,9 @@ var baseService;
var testService = {};
var rechercheService = {};
var exportService = {};
var wrapperService = {};
module.exports.initWebservice = function(params){
wrapperService.initWebservice = function(params){
// force params to be an obj
params = params || {};
......@@ -25,6 +26,42 @@ module.exports.initWebservice = function(params){
});
};
/**
* Converts a CSV to JSON
* @param params {header: [], headerLine}
* @returns {Promise<any>}
*/
wrapperService.parseCSV = function(params, data){
return new Promise(
function (resolve, reject) {
let string = data.split("\n");
let result = [];
let exit = true;
for (let line = 0; line < string.length; line++) {
var header = params.header;
if (!exit || string[line] == "__________") {
exit = false;
continue;
}
if (line > headerLine) {
var temp = string[line].split(";");
var obj = {};
for (let prop = 0; prop < temp.length; prop++) {
obj[header[prop]] = temp[prop];
}
result.push(obj);
}
}
resolve(result);
})
}
exportService.TabellenExport = function(requestParameter){
console.log("TabellenExport", "Starting");
......@@ -62,7 +99,6 @@ exportService.TabellenExport = function(requestParameter){
});
})
}
exportService.AuspraegungInformation = function(requestParameter){
// force params to be an obj
......@@ -81,7 +117,6 @@ exportService.AuspraegungInformation = function(requestParameter){
});
})
};
exportService.MerkmalInformation = function(requestParameter){
// force params to be an obj
......@@ -101,7 +136,6 @@ exportService.MerkmalInformation = function(requestParameter){
});
})
};
exportService.ErgebnisExport = function(requestParameter){
// force params to be an obj
......@@ -148,7 +182,6 @@ testService.whoami = function() {
});
})
}
rechercheService.MerkmalsKatalog = function(requestParameter){
// force params to be an obj
......@@ -221,6 +254,12 @@ rechercheService.AuftraegeKatalog = function(requestParameter){
var sendRequest = function(service,requestParams) {
return new Promise(function (resolve, reject) {
......@@ -303,3 +342,4 @@ var addAuswahl = function (param) {
module.exports.exportService = exportService;
module.exports.testService = testService;
module.exports.rechercheService = rechercheService;
module.exports.wrapperService = wrapperService;
\ No newline at end of file
{
"name": "genesis-online-wrapper",
"version": "0.0.3",
"version": "0.0.5",
"description": "Node.js wrapper for the germany genesis online databases",
"main": "index.js",
"scripts": {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment