Skip to content

Instantly share code, notes, and snippets.

@travist
Created August 22, 2016 18:26
Show Gist options
  • Save travist/d6331cad24328ebd16a77c7d495e02c4 to your computer and use it in GitHub Desktop.
Save travist/d6331cad24328ebd16a77c7d495e02c4 to your computer and use it in GitHub Desktop.
Form.io Reporting API
var request = require("request");
var options = {
method: 'POST',
url: 'https://myproject.form.io/report',
headers: {
'content-type': 'application/json',
'x-jwt-token': '..... TOKEN GOES HERE .....'
},
body: [
{
"$match": {
"form": {
"$in": [
"ObjectId('123123123123123')",
"ObjectId('234234234234234')"
]
}
}
},
{
"$group": {
_id: "$data.case._id",
title: {
"$first": "$data.case.data.title"
},
total: {"$sum": 1},
approved: {"$sum": {
"$cond": {
if: {"$eq": ["$data.status", "approved"]},
then: 1,
else: 0
}
}},
pending: {"$sum": {
"$cond": {
if: {"$eq": ["$data.status", "pending"]},
then: 1,
else: 0
}
}}
}
}
],
json: true
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment