This repository was archived by the owner on Apr 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple-custom-app.js
More file actions
100 lines (88 loc) · 2.36 KB
/
Copy pathsimple-custom-app.js
File metadata and controls
100 lines (88 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
var express = require("express");
var app = express();
var _ = require("lodash");
var bodyParser = require("body-parser");
var resolve = require("path").resolve;
var fs = require("fs");
app.use(bodyParser.json());
var sendCsvFileAsIs = function (req, res) {
res.sendFile(resolve("./data/" + req.body.source + ".csv"));
};
var sendFilteredJsonFile = function (req, res) {
var data = require("./data/" + req.body.source + ".json");
var companyFilter = req.body.filter["company"] || [];
var price = req.body.filter["price"] || 0;
if (!_.isEmpty(companyFilter)) {
data = _.filter(data, function (row) {
return _.includes(companyFilter, row.company);
});
}
data = _.filter(data, function (row) {
return row.price >= price;
});
res.json(data);
};
var dataProcessor = {
flowers: sendCsvFileAsIs,
salaries: sendCsvFileAsIs,
stocks: sendFilteredJsonFile,
};
var getSources = function () {
return [
{ id: "flowers", name: "Flowers" },
{ id: "salaries", name: "Salaries" },
{
id: "stocks",
name: "Stocks",
filter: [
{
id: "price",
title: "Bottom Price",
optional: true,
type: "number",
},
{
id: "company",
title: "Companies",
optional: true,
placeholder: "Select companies",
private: true,
type: "multilist",
data: [
{ title: "Apple", value: "AAPL" },
{ title: "Microsoft", value: "MSFT" },
{ title: "IBM", value: "IBM" },
{ title: "Amazon", value: "AMZN" },
],
},
],
},
];
};
app.get("/logo", function (req, res) {
res.sendFile(resolve("./logo.svg"));
});
app.get("/", function (req, res) {
var app = {
name: "Vizydrop Samples",
version: "2.0",
description: "The set of samples to check vizydrop in action",
authentication: [
{
id: "none",
name: "This information is public",
description:
"There is no any authentication required. Just press [Connect] button and proceed to charts beauty",
},
],
sources: getSources(),
};
res.json(app);
});
app.post("/validate", function (req, res) {
res.json({ name: "Vizydrop Samples" });
});
app.post("/", function (req, res) {
dataProcessor[req.body.source](req, res);
});
app.listen(process.env.PORT || 8080);