Skip to content
Permalink
Browse files

Add crm queryByDate.

Add an example how to use it.
  • Loading branch information...
albertosantini committed Jun 27, 2018
1 parent cf74b5e commit 2fc9cb15de1d62b01c5bf414780d5d2ed3039e10
Showing with 36 additions and 4 deletions.
  1. +31 −0 examples/crm.js
  2. +5 −4 lib/crm.js
@@ -0,0 +1,31 @@
"use strict";

const os = require("os");
const crm = require("../lib/crm");

crm.configure({

liveDomain: os.hostname(),

// liveDomain: "foo.com",
liveUrl: process.env.CONPA_LIVE_URL || "http://localhost:5984",
liveDb: "conpa",
testingUrl: process.env.CONPA_TEST_URL || "http://localhost:5984",
testingDb: "conpa-staging",
design: "ConPA"
});

crm.queryByDate({
metric: "ret",
beginRefDate: "2017/01/01",
endRefDate: "2017/12/31",
limit: 3,
sort: "asc"
}, (err, res) => {
if (err) {
console.warn(err);
return;
}

console.warn(res);
});
@@ -132,23 +132,23 @@ function getView(name, options, callback) {
});
}

function queryByDate({ // eslint-disable-line
function queryByDate({
metric, // "perf", "risk", "ret"
beginRefDate, // yyyy/mm/dd
endRefDate, // yyyy/mm/dd
limit = 3,
sort = "asc" // "asc, "desc"
}, callback) {
const couch = getCouchDBInstance();
const view = `${couch.couchDesign}/_view/_find`;
const url = `${couch.couchDB}/_find`;

request({
method: "POST",
url: couch.couchDB + view,
url,
body: {
selector: {
[metric]: {
$gt: -42
$gt: -9999
},
ref: {
$gt: beginRefDate,
@@ -172,6 +172,7 @@ function queryByDate({ // eslint-disable-line
callback(error, error || JSON.parse(data));
});
}
exports.queryByDate = queryByDate;

function getPortfolioCount(callback) {
getView("viewByRef", {

0 comments on commit 2fc9cb1

Please sign in to comment.
You can’t perform that action at this time.